input
name a1 a2 a3
g1 0.8 0.4 0.2
g2 -0.2 -0.6 -0.7
g3 0.1 0.6 0.8
g4 0.1 0 0
g5 -0.2 -0.2 -0.2
g6 -0.1 -0.9 -0.9
g7 0 0 0.2
output
a1:2
a2:0
a3:0
I use the following
awk '{if ($2>=0.5) print $1"\t""1"; else if($2<=-0.5) print $1"\t""-1"}' input |awk '{ sum+=$2} END {print sum}'
2
awk '{if ($3>=0.5) print $1"\t""1"; else if($3<=-0.5) print $1"\t""-1"}' input |awk '{ sum+=$2} END {print sum}'
0
awk '{if ($4>=0.5) print $1"\t""1"; else if($4<=-0.5) print $1"\t""-1"}' input |awk '{ sum+=$2} END {print sum}'
0
But I have many columns. Is there anyway I can apply the same command looping over all the columns that gives the above output at once? thanx in advance.