o*******e 发帖数: 31 | 1 I want to use awk to realize following goal:
when the line matches some Regular Expression, parsing
the line and output.
if the line doesn't match, don't make parsing and output
the original line.
I try to use if block like this:
if ( $0 ~ /expression/ )
{ printf "total energy =" ,$NF}
else
{printf $0}
But it doesn't work.
/expression/ {print "total energy =", $NF}
can find the desired line and output as I wish, but
I lose the control of other lines.
I don't know what's wrong with my cod | h******a 发帖数: 198 | 2 /expression/{print "total energy=",$NF};!/expression/{print}
【在 o*******e 的大作中提到】 : I want to use awk to realize following goal: : when the line matches some Regular Expression, parsing : the line and output. : if the line doesn't match, don't make parsing and output : the original line. : I try to use if block like this: : if ( $0 ~ /expression/ ) : { printf "total energy =" ,$NF} : else : {printf $0}
| o*******e 发帖数: 31 | 3 Thx!
BTW, what does the semicolon mean?
How to use "if" to solve the problem?
【在 h******a 的大作中提到】 : /expression/{print "total energy=",$NF};!/expression/{print}
| o*******e 发帖数: 31 | 4
How does awk deal with a series of pattern {action} ?
excute all actions for one line first
or excute one action for all lines first?
【在 o*******e 的大作中提到】 : Thx! : BTW, what does the semicolon mean? : How to use "if" to solve the problem?
|
|