Count the number of independent IPs through nginx logs Xinxiang independent IP independent ipvps independent public network i

WBOY
Release: 2016-07-29 08:53:05
Original
1262 people have browsed it

使用uniq命令可以过滤掉文本文件中重复的行以及统计等等功能,同时它也接受来着管道的输入。借助awk,甚至可以对行中的列进行操作,例如统计nginx日志信息中独立ip数、列出访问次数最多的ip等。需要注意的地方是uniq只对相连的行进行处理,所以一般情况下要先进行sort操作。

假设有名为test.txt文本文件,其信息为:

<span>ab
ac
ab
ac
ac
ad
ac</span>
Copy after login

执行命令

<span>uniq test.txt</span>
Copy after login

此时得到的结果为:

<span>ab
ac
ab
ac
ad
ac</span>
Copy after login

从结果可以看到,这里只对3,4行的ac进行过滤,这显然不是我们需要的结果,原因就是uniq只对相连的行进行运算了,现在先用sort排序,然后再执行uniq,例如:

<span>sort test.txt | uniq</span>
Copy after login

这时的结果为:

<span>ab
ac
ad</span>
Copy after login

可以看到再没有重复行了。

例如通过nginx日志统计独立ip的个数:

<span>awk '{print $1}' /path-to-log-dir/access.log | sort | uniq | wc -l</span>
Copy after login

查询访问最多的前10个ip

<span>awk '{print $1}' /path-to-log-dir/access.log  | sort | uniq -c | sort -nr | head -10</span>
Copy after login

原文链接http://www.netingcn.com/linux-uniq.html

以上就介绍了通过nginx日志统计独立ip的个数,包括了nginx,独立ip方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!