![]() |
calculating average segment after segment using AWK
Dear Experts,
I would like to calculate average over few hundred thousands lines of data. I would like to use awk to that but I just could not figure out how the syntax to this. The sample data as below: Code:
5 31.879999 at the end I want final data to be Code:
5 averageAppreciate any help in advance. Thank you |
Hi,
Try this: Code:
awk '{ a[$1] += $2 ; b[$1]++ } END { for ( cnt in a) { print cnt , "\t", a[cnt]/b[cnt] } }' input | sort -nCode:
$ awk '{ a[$1] += $2 ; b[$1]++ } END { for ( cnt in a) { print cnt , "\t", a[cnt]/b[cnt] } }' input | sort -n |
HI,
Thank you so much for your kind help. Regards Vijay |
| All times are GMT -5. The time now is 09:08 PM. |