I have a data of thousand lines like this:
1.01
2.01
3.01
4.01
5.012
6.019
7.01
8.013
9.01
10.01
11.01
12.01
13.01
14.01
15.5
I would like to get averages of every 9 lines (or general nth line if 9 is two short). I would like to print out from the line (n-1)/2 to line [line_number - (n-1)/2], where line_number is the total number of lines in the data file, n=9 for this example.
This command does not work average like what I expected:
line_number=$(wc -l test.txt)
awk '{sum[$1]=sum[$1] + $1; nr[$1]++} END {for (a in sum) {print a, sum[a]/nr[a]}}' test.txt
Expected results:
1.01
2.01
3.01
4.01
5.012 5.011555556 #(1.01+2.01+3.01+4.01+5.012+6.019+7.01+8.013+9.01)/9
6.019 6.011555556 #( 2.01+3.01+4.01+5.012+6.019+7.01+8.013+9.01+10.01)/9
7.01 7.011555556 #( 3.01+4.01+5.012+6.019+7.01+8.013+9.01+10.01+11.01)/9
8.013 8.011555556
9.01 9.011555556
10.01 10.01133333
11.01 11.06477778
12.01
13.01
14.01
15.5