开发者

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

开发者 https://www.devze.com 2023-01-04 11:14 出处:网络
How to print $2 by awk only if the fourth开发者_如何转开发 field is not 0 (zero). line=\"root13246 11314457 15: qsRw -m1\"

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

精彩评论

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