/* vim: set filetype=awk : */ # -*- awk -*- BEGIN { Cmeta = "=" Ccomment = "%" FS=OFS = "," Loud = 1 Prefix = "" Report = 1 } NR==1 { split("",Name,"") Cmeta = "^[ \t]*" Cmeta } { sub(Ccomment".*","") } /^[ \t]*$/ { next } sub(Cmeta,"",$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) { if (Prefix) printf Prefix OFS; if (Loud) print "what","n","min","mean","max","sd","sd/mean%"; if (Report) for(i in N) { mean = Sum[i]/N[i]; sd = sd(SumSq[i],Sum[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 }