How to use awk to print a particular section of input file -
i have input file this.
# #mdrun part of g r o m c s: # #go rough, oppose many angry chinese serial killers # @ title "dh/d\xl\f{}, \xd\f{}h" @ xaxis label "time (ps)" @ s0 legend "dh/d\xl\f{} \xl\f{} 0.1" @ s1 legend "\xd\f{}h \xl\f{} 0.05" @ s2 legend "\xd\f{}h \xl\f{} 0.15" 0.0000 -33.8598 1.71168 -1.66746 0.2000 -34.3949 1.73192 -1.702 0.4000 -31.8213 1.61262 -1.56193 0.6000 -32.3563 1.63639 -1.59224 0.8000 -33.6158 1.69898 -1.65539 1.0000 -32.5242 1.65055 -1.59363 1.2000 -33.7464 1.70708 -1.6607 1.4000 -33.0552 1.68563 -1.60985 1.6000 -32.9946 1.66834 -1.62445 1.8000 -31.6345 1.60933 -1.54529 2.0000 -33.1246 1.67736 -1.62769 2.2000 -33.9822 1.71743 -1.67394 2.4000 -32.4887 1.64732 -1.59384 2.6000 -30.0927 1.5349 -1.46508 on till 100000.0000
i want generate new file containing particular section( complete lines) 1000.0000-2000.0000 line containing "@" , "#". suggested me use awk , suggested code.
awk '(/^1000/,/^2000/) || /^[@#]/{print;}' inputfile > outputfile
which shows error.
awk: line 1: syntax error @ or near ||
i haven't used awk before have no idea how write code in awk. if can suggest how write proper code in awk or other sed. grateful.
you cannot combine range operator ,
||
in way, although there alternative in case:
awk '/^1000/,/^2000/; /^[@#]/' inputfile > outputfile
the semicolon separates 2 conditions. each condition true, default action (print line) carried out. problem if conditions clashed (you duplicate lines in output) doesn't apply here.
more generally, can use variable determine lines print:
awk '/^1000/{f=1} f||/^[@#]/; /^2000/{f=0}' inputfile > outputfile
this deals case 2 separate conditions may both true @ same time.
Comments
Post a Comment