awk filter by occurence of at least two columns

Hi,
Using AWK script I want to pick those rows that has AT LEAST TWO columns EACH has a count >=3.
i.e. two conditions: at least two columns, each of which has a count at least 3.
There must be a simple way to do this job, but could not figure it out by myself.
Input file (thousand of rows!):

a    0  0  0   3   1   4
b    0  0  2   0   5   1
c    3  0  0   0   1   0
d    2  0  0   5   4   1
e    7  0  4   4   1   0
f    8  0  0   0   1   3

Output file:

a    0  0  0   3   1   4
d    2  0  0   5   4   1
e    7  0  4   4   1   0
f    8  0  0   0   1   3

Any suggestion for this problem? Thanks a lot!

try this:

awk '{x=0;for(i=1;i<=NF;i++) if($i>=3) x+=1; if(x>2)print}' infile

Awesome!
Should the second condition be:

if (x>=2) print 

as my condition is "at least two columns" ?
Thanks a lot!

it should be x>2 because for 1st column ($i>=3) returns true, so "x" increments 1 for 1st column.

1 Like