开发者

awk + print the second field in line only if the four field is 0

How to print $2 by awk only if the fourth开发者_如何转开发 field is not 0 (zero).

line="root     13246 11314  457 15: qsRw -m1"

then awk will print 13246, but if

line="root     13246 11314  0 15: qsRw -m1"

then awk will not print anything


awk '$4!=0{print $2}' file

or just

awk '$4{print $2}' file

The syntax of awk is

awk '/pattern/{action}' file

the "pattern" part is actually an implicit "if" control flow structure. Therefore you can omit putting an "if" keyword.


awk '{if ($4) print $2;}' < inputfile
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜