bash - extract data date wise and do average calculation -
how extract data date wise , average calculation per date below shown output. last column average.
sun jul 5 00:00:02 ist 2015, 97 sun jul 5 00:02:01 ist 2015, 97 sun jul 5 00:04:02 ist 2015, 97 mon jul 6 00:00:01 ist 2015, 73 mon jul 6 00:02:02 ist 2015, 93 mon jul 6 00:04:02 ist 2015, 97 tue jul 7 00:00:02 ist 2015, 97 tue jul 7 00:02:02 ist 2015, 97 tue jul 7 00:04:01 ist 2015, 97 wed jul 8 00:00:01 ist 2015, 98 wed jul 8 00:02:02 ist 2015, 98 wed jul 8 00:04:01 ist 2015, 98 thu jul 9 00:00:02 ist 2015, 100 thu jul 9 00:02:01 ist 2015, 100 thu jul 9 00:04:01 ist 2015, 100 fri jul 10 00:00:01 ist 2015, 100 fri jul 10 00:02:02 ist 2015, 100 fri jul 10 00:04:02 ist 2015, 100 sat jul 11 00:00:01 ist 2015, 73 sat jul 11 00:02:01 ist 2015, 73 sat jul 11 00:04:02 ist 2015, 73 want output
jun 6 - 97 jun 7 - 86.66 ...
you can use awk:
awk -f ', ' '{ split($1, a, " "); k=a[2] ofs a[3]; if(!(k in c)) b[++n]=k; c[k]++; sum[k]+=$2 } end{ for(i=1; i<=n; i++) printf "%s - %.2f\n", b[i], (sum[b[i]]/c[b[i]]) }' file jul 5 - 97.00 jul 6 - 87.67 jul 7 - 97.00 jul 8 - 98.00 jul 9 - 100.00 jul 10 - 100.00 jul 11 - 73.00
Comments
Post a Comment