Flomp Flomp -4 years ago 93
Linux Question

awk - all rows where half of columns are bigger than x

As the title suggests I'm trying to find all rows in an large tsv file, where at least 50% of the columns have a value bigger than a value x using awk.

E.g for x=5:

9 6 7 2 3
0 1 2 7 6
1 3 8 9 10


should return

9 6 7 2 3
1 3 8 9 10

Answer Source

awk to the rescue!

$ awk -v t=5 '{c=0; for(i=1;i<=NF;i++) c+=($i>t)} c/NF>0.5' file

9    6    7    2     3
1    3    8    9    10
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download