由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - awk question
相关主题
reverse the lines?how to get part of a big text file?
can't run a simple c codeemacs how to concatenate two lines?
Some simple Unix questionsemacs中如何去指定一行
奇怪的 printf!! ksh programmingPerl: conditionally match multiple lines
how to set a path which is more than one line?a beginner's question
How to see line number in Emacs请问Soalris 8的cache line size 是多少?
what's the command to count the number of lines in a file?an AWK question?
Re: what's the command to count the number of lines in a file?[转载] guplot 怎么设置default?
相关话题的讨论汇总
话题: expression话题: line话题: awk话题: nf话题: output
进入Unix版参与讨论
1 (共1页)
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?

1 (共1页)
进入Unix版参与讨论
相关主题
[转载] guplot 怎么设置default?how to set a path which is more than one line?
Command line extend beyond a sing lineHow to see line number in Emacs
on-line help!!!what's the command to count the number of lines in a file?
How to use line type in GnuPLot?Re: what's the command to count the number of lines in a file?
reverse the lines?how to get part of a big text file?
can't run a simple c codeemacs how to concatenate two lines?
Some simple Unix questionsemacs中如何去指定一行
奇怪的 printf!! ksh programmingPerl: conditionally match multiple lines
相关话题的讨论汇总
话题: expression话题: line话题: awk话题: nf话题: output