awk统计ip访问量(一条命令)

对下面的1.log 文件进行统计,

要求: 统计出每个IP的访问量有多少? 提示,先awk过滤出ip,然后进行排序,统计重复数。

只用一条命令即可

awk ‘{STAT[$1]++};END{for(A in STAT) print STAT[A], A}’ 1.log|sort -nr|head -10

1.log   的大致格式:

200.104.118.180 – – [27/Jun/2018:10:47:34 +0800] “GET /games/search_game.php?typ
e=game&k=w2qsdw HTTP/1.1” 404 564 “http://www.xxwan.com/games/search_game.php?ty
pe=game&k=w2qsdw” “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTM
L, like Gecko) Chrome/57.0.2987.98 Safari/537.36” –
77.50.62.6 – – [27/Jun/2018:10:47:34 +0800] “GET /games/search_game.php?type=gam
e&k=w2qsdw HTTP/1.1” 404 564 “http://www.xxwan.com/games/search_game.php?type=ga
me&k=w2qsdw” “Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; Mo
zilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 3.5.30729)” –
90.189.159.36 – – [27/Jun/2018:10:47:34 +0800] “GET /games/search_game.php?type=
game&k=w2qsdw HTTP/1.1” 404 564 “http://www.xxwan.com/games/search_game.php?type
=game&k=w2qsdw” “Mozilla/4.0 (compatible; MSIE 6.0; Windows XP 5.1) Lobo/0.98.4”

发表评论

电子邮件地址不会被公开。 必填项已用*标注