Thursday, September 19, 2002

Proof that I'm a unix weenie. I've got a bunch of lines in a web server log file that look like this:

[19/Sep/2002:20:07:50][19141.88][-sched:31-] Notice: ep_email_alerts (1): finished processing user alerts for 20 of 452 total users in 00:07:19 (21.00 sec/user)

I want to know the average "sec/user" value for all of these lines and I do this with one command line:

% grep sec/user gateway108-error.log | awk -F\( '{print $3;}' | awk -F. 'BEGIN {count = 0; sum = 0;} {sum = sum + $1; count = count+1;} END { printf("count = %d\nsum = %d\navg = %.2f\n",count,sum,(sum*1.0)/count);}'

I didn't say it was a simple command line. Here's what the output looks like:

count = 115
sum = 2229
avg = 19.38

So there.

No comments: