BEGIN { FS = ","; OFS = ","; Pred = 30; } { Mre = $8; SumMre += Mre; SumMreSq += Mre^2; if (Mre < Pred) PredN++ } END { Mmre = SumMre/NR; Pred30 = 100*(PredN/NR); SdMre = sd(SumMreSq,SumMre,NR); print Mmre, Pred30, SdMre; } function sd(sumSq,sumX,n) { return sqrt((sumSq-((sumX*sumX) / n)) / (n-1)) }