Apache Logs: Count top 10 URLs by bytes served
I have an Apache log format file. Example string:
fj5020.inktomisearch.com - - [01/Oct/2006:06:35:59 -0700] "GET /example/When/200x/2005/04/27/A380 HTTP/1.0" 200 4776 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
where 4776 is served page size in bytes. I'd like to output top 10 URLs b开发者_运维知识库y served traffic. I'm stuck with the problem of summing all sizes of each unique page (the size of a page can also be variable). Any ideas how to do it in Bash or/and AWK?
does this work for you?
awk '{a[$7]+=$10}END{for(x in a)print x, a[x]}' yourLogfile|sort -r -n -k2|head -n10
Lots of ways to do it. Here's one.
total=0
last_site=
while read site size ; do
if [ "$site" != "$last_site" ] ; then
[ ! -z "$last_site" ] && printf '%s %d\n' "$last_site" $total
total=0
last_site="$site"
fi
let total+=$size
done < <(awk '{print $1, $10}' log | sort)
printf '%s %d\n' "$last_site" $total
精彩评论