# How to count the number of occurrences of a number larger than x, from every column?

I'm trying to figure out how to count the number of occurrences of values that are greater than some number (i.e. 0.1) in each column and then print that value out for each column. Here would be some sample data, except for this would need to be general, i.e. work for any number of columns:

``````Data     Sample1     Sample2     Sample3
row1      0.05         0.12        5.00
row2      0.00         5.00        8.75
row3      1.19         0.00        6.78
``````

And then the desired output could be something like (counting the numbers greater than 0.1):

``````Sample1:  1
Sample2:  2
Sample3:  3
``````

Perl, awk, or coreutils would be fine, I just need to build it into a bash script to output some stats on the table of data.

I can count one column, but I don't know how to do it for all of them:

``````gawk -F"\t" 'NR>1 {if (\$2>0.1) print \$1;}' | wc -l
``````

Thanks in advance for the help.

``````awk '{for(i=2;i<=NF;i++){if(NR==1)h[i]=\$i;else if(\$i>0.1)x[i]++}}END{for(i in x){print h[i]": "x[i]}}'
• Maybe like this: `gawk 'NR==1{for(i=1;i<=NF;i++)h[i]=\$i;} NR>1{for(i=2;i<=NF;i++){if(\$i>0.1)x[i]++}}END{for(i in x){print h[i]": "x[i]}}'` Dec 22, 2014 at 22:33