How to calculate the average in linux?
I have a file like this: ID Math Sci Eng Average 230 70 - 50 123 50 50 60 223 - 80 90
I need the output like this:
ID Math Sci Eng Average 230 70 - 50 60 123 50 50 60 53.33 223 - 80 90 85
I am using this code, but I am only able to get the total:
awk '/^[0-9]/ {for (i=2; i<=NF; i++) {tot+=$i}; avg=tot/cnt[i]; print $1 "\t" avg}' I calculated total using the above; and thought that I will be able to count the no. but its giving me an error .. Please help me, I am new to this field .. Thanks :)
perl -lpe 'if(/^\d/){local($a,@_,$s,$")=split/\s+/;map{$s+=$_;++$"if/\d/}@_;$_.="\t".$s/$"}'