I have a large data file consisting of many colums, and i would like to bin the (say) third column and output to a separate file.
By binning i mean the following:
I have a list of numbers say:
1
4
1
1
1
1
I want the average of sets of (say) three consecutive numbers.
My final output should be
2
1
The first entry is the average of
1
4
1
And the second entry is the average of the next three numbers,
1
1
1
How do i achieve this using awk?
Use this awk command:
awk '{sum+=$1} NR%3==0 {print sum/3; sum=0}' inFile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With