Agreed it would be nice to show your efforts to this point.
I think a simple awk script would be an easy solution which would also provide decimal average values which a shell script will not do.
By way of encouragement I wrote a quick and dirty awk which does the following pseudo-code (assumes dates are not interleaved, prints average for each date):
Code:
BEGIN {
#...initialize date match, count and total vars
}
Same date{
#Increment count, add amount to total
next
}
Count > 0{
#Change of date so print last date and average, reset date match, count and total vars
next
}
{
#First line, set initial date match, increment count, set total to amount
}
END{
#Last line, print last date and average
}
When run with your example data it produces this...
Code:
awk -f rain.awk rain_data
Average: 2012 12 5 13
Average: 2013 04 3 16.5
I leave the actual code as an exercise for you! (Pretty simple!)