I have access log file with data only per 1 day like:
10.2.21.120 "-" - [26/Jan/2013:19:15:11 +0000] "GET /server/ad?uid=abc&type=PST HTTP/1.1" 202 14 10
10.2.21.120 "-" - [26/Jan/2013:19:17:22 +0000] "GET /server/ad?uid=abc&type=PST HTTP/1.1" 204 14 9
10.2.22.130 "-" - [26/Jan/2013:19:27:53 +0000] "GET /server/ad?uid=abc&type=PST HTTP/1.1" 200 14 8
I am using the following command:
awk '$9 == 200 { s++ } END { print s / NR * 100; }' access.log
This awk may help you
Test
What it does
{count[$5]++}
arraycount
stores the number of occurence of each hour from the log file.$12 == 200 { hour[$5]++}
Now it the log is success, that is$12 == 200
then the corresponding value inhour
array is incremented.So
count[13]
will contain total enteries from hour13
where ashour[13]
would contain count of succuessfull entriesEND { for (i in hour) print i, hour[i]/count[i]*100 }
prints thehour, percentage