Calculate average time using a script

Hello,

I'm hoping to get some help on calculating an average time from a list of times (hour:minute:second).

Here's what my list looks like right now, it will grow (I can get the full date or change the formatting of this as well):

07:55:31
09:42:00
08:09:02
09:15:23
09:27:45
09:49:26
10:30:41
10:03:51
10:25:14
07:12:30
08:18:31
10:33:37
11:12:20

I'm guessing I can use awk or something, but I'm not quite sure how to get it to work.

Any help is appreciated.

Thanks,
Jared

Can you change the format to simply the number of seconds total duration? If not, I would just convert each line to seconds and use that as to generate your average. Convert the average back to whatever format you want to read.

awk -F':' 'BEGIN{total=0;} {total+=(($1*3600)+($2*60)+$3);} END{printf "%10d\n",(total/NR)}' Edit7

Thanks curleb!

What's the easiest way to convert this into hour:minute (or hour:minute:second) format?

I'd say the easiest would be to just reverse the calculation within the END{} statement. Instead of just printing the Average, you'd want to go ahead and put it back onto the horse it rode in on:

$ awk -F':' 'BEGIN{total=0;} {total+=(($1*3600)+($2*60)+$3);} END{a=(total/NR); printf "%02d:%02d:%02d\n",(a/3600),((a/60)%60),(a%60)}' Edit7