BEGIN { MetaC = "=" CommentC = "%" FS=OFS = "," } NR==1 { split("",Name,"") MetaC = "^[ \t]*" MetaC } { sub(CommentC".*","") } /^[ \t]*$/ { next } sub(MetaC,"",$1) { for(I=1;I<=NF;I++) Name[I]=$I; next} { for(I=1;I<=NF;I++) { Max[I]= (I in Max) ? ($I > Max[I] ? $I : Max[I]) : $I; Min[I]= (I in Min) ? ($I < Min[I] ? $I : Min[I]) : $I; N[I]++ Sum[I] += $I SumSq[I] += $I^2 push(Data,I,$I); } } END { report() } function report( sd,mean,i,label) { print "what","n","min","mean","max","sd","sd/mean%"; for(i in N) { mean = Sum[i]/N[i]; sd = sd(SumSq[i],SumX[i],N[i]); label= (i in Name) ? Name[i] : i print label, N[i],Min[i],mean,Max[i], sd,int(100*sd/mean) | "sort -n" } } function sd(sumSq,sumX,n) { return sqrt((sumSq-((sumX*sumX) / n)) / (n-1)) } function push(a,k,v, i) { i= ++a[k,0]; a[k,i]=v; return v }