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
精彩评论