I have a txt file that shows the average sunspot data for each month of the year between 1749 and 2005.
(* Month: 1749 01 *) 58
(* Month: 1749 02 *) 63
(* Month: 1749 03 *) 70
(* Month: 1749 04 *) 56
(* Month: 1749 05 *) 85
(* Month: 1749 06 *) 84
(* Month: 1749 07 *) 95
(* Month: 1749 08 *) 66
(* Month: 1749 09 *) 76
(* Month: 1749 10 *) 76
(* Month: 1749 11 *) 159
(* Month: 1749 12 *) 85
(* Month: 1750 01 *) 73
(* Month: 1750 02 *) 76
(* Month: 1750 03 *) 89
(* Month: 1750 04 *) 88
Etc.
I need to average the 12 months for each year. So 1749 should equal 81. Averaging the $6 row with awk seems to be simple.
awk ' {sum += $6}
END { print sum/ NR } ' sunspot.txt
However, I don't know where to start as far as using control structures in Awk to incrementally average each of the 12 numbers for the years between 1749 and 2005.