AWK - variables

I have a data file like this:

49960	1157	32390	1227	1268	
	31		8		21
12		115		18493	67
250	2		2	237704	369658
52	21	312	38	27746	3174
19	160	9	555	6337	6071
				43	33

I want to separate the field to three groups, $1 and $2 are the first group, $3 and $4 are the second group, $5 and $6 are the third group. I want output the records that more than two group have a total value>100.
This is my code, and I can't get it. I'm a new guy in shell. Thank you!

#! /bin/awk -f
a=0
b=0
c=0
BEGIN {
     FS="\t"
}
{

   if ($1+$2 >=100) {
                              a=1
                     }
}
 {
   if ($3+$4 >=100) {
                              b=1
                     }
}
{
   if ($5+$6 >=100) {
                              c=1
                     }
}
END {
             if (a+b+c >= 2) {
                 print $0
       }
}

But I get the results.
Thank you!

Your text said "I want output the records that more than two group have a total value>100.", but your code says:

             if (a+b+c >= 2) {
                 print $0
       }

which would print the line if two OR MORE groups have a total value >= 100.

The following script prints lines if more two or more groups' sums are >= 100.

awk -F"\t" '($1+$2>=100)+($3+$4>=100)+($5+$6>=100)>=2' input

If you want all three groups' sums to be >= 100, change the >2 to >=2 or ==3 or change the entire script to:

awk -F"\t" '($1+$2>=100)&&($3+$4>=100)&&($5+$6>=100)' input
1 Like