Hi, I only have a very limited understanding and experience with writing code and I was hoping I could get some help.
I have a dataset of two columns (txt format, numbers in each row separated by a tab)
Eg.
1 5
2 5
3 6
4 7
5 6
6 6
7 5
8 3
9 2
10 1
I want to get the average of column 2 for the first three numbers - so 5,5,6 - then move down one position for the average of the next three - so 5,6,7 - then average the next lot - 6,7,6 - etc, moving down the whole column. So then I'll end up with a column of averages.
5.33
6
6.33
6.33
...etc
This is my code so far...
head -3 datafilename.txt | tail -3 | awk '{sum +=$2} END {print sum/3}'
...which will give me the average of the first bracket of three numbers.
I've been trying to use a for loop to move the averaging down the column but I'm having difficulty making it work.
Something like...
BEGIN {for (i=1; i++)} head -$i datafilename.txt | tail -3 | awk '{sum +=$2} END {print sum/3}'
But I have no idea really (you can probably tell).
Any suggestions would be greatly appreciated,
Emred Skye.