【发布时间】:2012-03-26 13:48:12
【问题描述】:
我有一个文本文件格式的日志文件。日志文件看起来像下面的格式
220.227.40.118 - - [06/Mar/2012:00:00:00 -0800] "GET /mysidebars/newtab.html
HTTP/1.1" 404 0 - -
220.227.40.118 - - [06/Mar/2012:00:00:00 -0800] "GET /hrefadd.xml HTTP/1.1"
204 214 - -
59.95.13.217 - - [06/Mar/2012:00:00:00 -0800] "GET /dbupdates2.xml HTTP/1.1"
404 0 - -
111.92.9.222 - - [06/Mar/2012:00:00:00 -0800] "GET /mysidebars/newtab.html
HTTP/1.1" 404 0 - -
120.56.236.46 - - [06/Mar/2012:00:00:00 -0800] "GET /hrefadd.xml HTTP/1.1"
204 214 - -
49.138.106.21 - - [06/Mar/2012:00:00:00 -0800] "GET /add.txt HTTP/1.1" 204
214 - -
117.195.185.130 - - [06/Mar/2012:00:00:00 -0800] "GET
/mysidebars/newtab.html HTTP/1.1" 404 0 - -
122.160.166.220 - - [06/Mar/2012:00:00:00 -0800] "GET
/mysidebars/newtab.html HTTP/1.1" 404 0 - -
117.214.20.28 - - [06/Mar/2012:00:00:00 -0800] "GET /welcome.html HTTP/1.1"
204 212 - -
117.18.231.5 - - [06/Mar/2012:00:00:00 -0800] "GET /mysidebars/newtab.html
HTTP/1.1" 404 0 - -
我想使用 python 查找日志文件中存在的每个唯一 IP 地址。
【问题讨论】:
-
既然
perl -lane 'print $F[0] unless $seen{$F[0]}++' logfile1 logfile2 logfile3已经为您完成了这项工作,为什么还要使用 python? -
@tchrist 应该扩展为答案
-
@tchrist 但我的要求是在 python 上。
-
$ sort -uk1,1已经完成这项工作了,为什么还要使用 perl?
标签: python ip-address