通过访问日志access.log统计IP和每个地址访问的次数
1
2
|
101.226.61.184 - - [22
/Nov/2015
:11:02:00 +0800]
"GET /mobile/sea-modules/gallery/zepto/1.1.3/zepto.js HTTP/1.1"
200 24662
"http://m.oldboyedu.com/mobile/theme/oldboyedu/home/index.html"
"Mozilla/5.0 (Linux; U; Android 5.1.1; zh-cn; HUAWEI CRR-UL00 Build/HUAWEICRR-UL00) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.4 TBS/025478 Mobile Safari/533.1 MicroMessenger/6.3.7.51_rbb7fa12.660 NetType/3gnet Language/zh_CN"
101.226.61.184 - - [22
/Nov/2015
:11:02:00 +0800]
"GET /mobile/theme/oldboyedu/common/js/baiduAnalytics.js HTTP/1.1"
200 526
"http://m.oldboyedu.com/mobile/theme/oldboyedu/home/index.html"
"Mozilla/5.0 (Linux; U; Android 5.1.1; zh-cn; HUAWEI CRR-UL00 Build/HUAWEICRR-UL00) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.4 TBS/025478 Mobile Safari/533.1 MicroMessenger/6.3.7.51_rbb7fa12.660 NetType/3gnet Language/zh_CN"
|
方法1:
1
2
3
4
5
|
awk
'{s[$1]++}END{for (i in s) print s[i],i}'
access.log |
sort
-rn
5 101.226.61.184
2 27.154.190.158
2 218.79.64.76
1 114.94.29.165
|
方法2:
1
2
3
4
5
|
awk
'{print $1}'
access.log |
sort
|
uniq
-c|
sort
-rn
5 101.226.61.184
2 27.154.190.158
2 218.79.64.76
1 114.94.29.165
|
awk数组还不是很理解?
往期题目:awk数组统计
往期题目:awk累计相加
常见问题:初学awk数组会遇到的几个常见问题
今天是每日一题陪伴大家的第36天,期待你的进步。
对于题目和答案的任何疑问,请在博客评论区留言。
往期题目索引
http://lidao.blog.51cto.com/3388056/1914205
本文转自 李导 51CTO博客,原文链接:http://blog.51cto.com/lidao/1919766