bash - Calculate mean and standard deviation for a column -
bash - Calculate mean and standard deviation for a column -
i z r 1 -30 3.5 2 -30 3.4 3 -30 3.6 ... 10 -30 4.2 1 -29.5 4.6 2 -29.5 2.8 3 -29.5 3.4 .... 10 -29.5 3.6 1 -29.0 2.5 2 -29.0 2.6 3 -29.0 3.0
i have file contents 3 column (above) . except first line (i z r), info file has 600 rows. first thought using command split 3rd column 10-lines-continuos sections, , utilize script calculate means , sd each section ("i" 1 10). after that, want set results file (result.dat).the result file content 3 column below: z means sd tried scripts below. don't know how combine them in 1 script file.
10 = split($3, array, " ") begin {n=0 ; s=0; ss =0} nf=10 {n++; s+= $3; ss == $3;} end { means=(s)/10 sd=sqrt((ss-m)*(ss-m))/10 prin $2 $means $sd}' data.dat >> result.dat
please help me. give thanks much.
#!/usr/bin/awk -f { s += $3; ss += $3*$3; if ($1 == 10) { print $2, s/10, sqrt((ss-s*s/10)/10) >"result.dat"; s = ss = 0 } }
bash awk
Comments
Post a Comment