perl - Sum of multiple colums -
i have o/p file below , i'm looking bash , perl solution:
aggregate total used avail capacity aggr0 100 59 41 41% aggr1 200 100 100 50% aggr2 300 150 150 50% aggr3 400 200 200 50%
i calculate sum of individual column except col-1. final state should this:
aggregate total used avail capacity aggr0 100 59 41 41% aggr1 200 100 100 50% aggr2 300 150 150 50% aggr3 400 200 200 50% ========================================================= 1000 509 460 50.9% (used % of aggr's)
infile file data in perl -ape 'next if $.==1; $i (1..4) { $s[$i] += $f[$i]; } end { $s[4]=sprintf("%.2f%%",$s[2]/$s[1]*100); $"="\t";print "total\t\t @s\n";}'
Comments
Post a Comment