2011-09-27 27 views
0

我有一個Apache日誌格式文件。示例字符串:Apache日誌:計數排名前10的URL按字節服務

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)" 

其中4776頁面大小以字節爲單位。我想通過提供的流量輸出前10個網址。我堅持總結每個獨特頁面的所有大小的問題(頁面的大小也可以是可變的)。任何想法如何在Bash或/和AWK中做到這一點?

回答

5

這個工作適合您嗎?

awk '{a[$7]+=$10}END{for(x in a)print x, a[x]}' yourLogfile|sort -r -n -k2|head -n10 
+0

謝謝,這是我需要的。非常感激。 – bvk256

0

很多方法可以做到這一點。這是一個。

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