Blogger Information
Blog 11
fans 0
comment 0
visits 16620
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
利用shell脚本统计文件中出现次数最多的IP
提百万的博客
Original
3088 people have browsed it

使用linux命令或者shell实现:

统计这个文件中出现次数最多的前10个IP。

cat ip.txt | sort | uniq -c | sort -k1,1nr | head -10

每一行的第二段字符

   文件格式             192.168.1.1– - [02/Jul/2010:23:44:59 +0800] “GET / HTTP/1.1″ 200 19

cat ip.txt | awk ‘{print $1}’|sort | uniq -c | sort -k1,1nr | head -10


  主要考察对sort、uniq命令的使用,相关解释如下,命令及参数的详细说明请自行通过man查看,简单介绍下以上指令各部分的功能:

sort:  对单词进行排序

uniq -c:  显示唯一的行,并在每行行首加上本行在文件中出现的次数

sort -k1,1nr:  按照第一个字段,数值排序,且为逆序

head -10:  取前10行数据


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!