Wednesday, December 5, 2012

How to select columns from file with two or more numeric criteria in Unix using awk

To select lines from files that contain specific numeric criteria in two or more columns use awk:

awk -F "|" '{ if ( $2 > 10 || $3 > 10 || $4 > 10 && $5 < 10 ) print $0 }'

-F "|" defines the delimiter if necessary, in case of tab delimited file this is not necessary.

$2 is the second column etc.

so this command will select all lines with number greater than 10 in either 2nd 3rd or 4th column and that have number less than 10 in 5th column.

No comments:

Post a Comment