아직미분류2011. 7. 21. 22:21
grep sth *.out | awk 'BEGIN {sum=0;} {sum+=$4;} END {avg=sum/NR; printf "%.4f\n", avg;}'
str=`grep "sth" *.out |
awk 'BEGIN {sum=0; sumsq=0;} NR == 1 {min=$4; max=$4}
{sum+=$4; sumsq+=$4*$4;} min > $4 {min=$4} max < $4 {max=$4}
END {avg=sum/NR; stddev=sqrt(sumsq/NR - avg**2);
printf "sth: %.4f & %.4f & %.4f %.4f", min, avg, max, stddev;}'`
# This awk program transposes a table.
# Output is a tab-separated table, but separator can be easily modified.
# Usage: awk -f transpose.awk input_file
BEGIN {
        p = 0 
}
{
        for (i=1; i<=NF; ++i) {
                a[NR,i] = $i
        }   
}
NF > p { 
        p = NF
}
END {
        for (j=1; j<=p; ++j) {
                str = a[1,j]
                        for (i=2; i<=NR; ++i) {
                                str = str"\t"a[i,j]
                        }   
                print str 
        }   
}
Posted by asdfzxcv