avatar
o*e
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
avatar
h*a
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}

avatar
o*e
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}
avatar
o*e
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?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。