in reply to averaging a group of lines with numeric value in a text file
Now do a simple aveperl -ane '{print $F[5]," ",$F[6],"\n";}' < dat.txt -135.185 178.150 -49.668 -31.158 ... snip -81.417 52.986 -83.126 -56.051
Just guessing what is meant by "5 groups". This example uses the contents of Field 3 ( counting from 0 ) to do the groupingperl -ane '{$t5+=$F[5]; $t6+=$F[6]; $t+=1} END{print $t5/$t," ",$t6/$t,"\n";}' < dat.txt -85.6206666666667 30.2721333333333
perl -ane '{$t5{$F[3]}+=$F[5]; $t6{$F[3]}+=$F[6]; $t{$F[3]}+=1} END{foreach $i (keys %t5) {print "Group $i ",$t5{$i}/$t{$i}," ",$t6{$i +}/$t{$i},"\n";}} ' < dat.txt Group S -75.969 10.2868 Group G -108.8372 73.3412 Group M -72.0558 7.1884
|
|---|