shell之nginx:统计nginx日志里访问次数最多的前10个IP

//正常的过滤

[root@localhost tjm]# cat access.log | cut -d " " -f 1 |  sort | uniq -c | sort -nr | head -n 10
     33 172.68.133.11
     30 172.69.22.69
     27 172.68.142.144
     27 162.158.255.87
     26 172.68.141.221
     26 162.158.255.213
     25 172.68.189.164
     25 172.68.141.203
     25 162.158.255.11
     24 172.68.141.167

 


//使用awk过滤
[root@localhost tjm]# cat access.log   | awk -F ' ' '{print $1}' | sort | uniq -c | sort -nr | head -n 10
     33 172.68.133.11
     30 172.69.22.69
     27 172.68.142.144
     27 162.158.255.87
     26 172.68.141.221
     26 162.158.255.213
     25 172.68.189.164
     25 172.68.141.203
     25 162.158.255.11
     24 172.68.141.167

 

 
 
//加上>1.txt && cat 1.txt -n 显示前十IP的同时,使用cat -n 在前面显示第几行
[root@localhost tjm]# cat access.log | cut -d " " -f 1 |  sort | uniq -c | sort -nr | head -n 10 > 1.txt && cat 1.txt -n
     1      33 172.68.133.11
     2      30 172.69.22.69
     3      27 172.68.142.144
     4      27 162.158.255.87
     5      26 172.68.141.221
     6      26 162.158.255.213
     7      25 172.68.189.164
     8      25 172.68.141.203
     9      25 162.158.255.11
    10      24 172.68.141.167

 

 
posted @ 2020-10-14 15:23  alan海盐味的文章  阅读(1135)  评论(0)    收藏  举报