# example - gawk -f columnStDev.awk Columns="-3-" data/subsets/coc81_all.csv.converted # or gawk -f columnStDev.awk I=3 data/subsets/coc81_all.csv.converted BEGIN { FS=OFS="," Sum=0; SumSq=0; I=1; Columns=""; } NR==1 { for(x=1; x<=NF; x++) { target="-"x"-"; if (index(Columns, target)!=0) { I=x; } } } { Sum += $I SumSq += $I^2 } END { result = sd(SumSq,Sum,NR); print result; } function sd(sumSq,sumX,n) { val=(sumSq-((sumX*sumX) / n)) / (n-1) magval= val < 0 ? -1* val : val; return sqrt(magval) #return sqrt((sumSq-((sumX*sumX) / n)) / (n-1)) }