【发布时间】:2019-03-21 05:14:59
【问题描述】:
我是 python 新手。我想打开一个文件 logs.txt 并匹配每一行(日志条目)中的所有 IP 地址。
然后我会打印带有 IP 地址的日志条目的数量/计数。 到目前为止我所拥有的:
import re
#read the file
file = open("logile.txt")
lineList = []
for line in file:
match = re.search( r'^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}', line )
if match:
print("IP found in this line is: ", match.group())
现在我想打印具有此 IP 地址的日志条目数。如何将带有 IP 的每一行附加到我的 lineList 并打印计数?
【问题讨论】:
-
你的问题是什么?
-
我的帖子最后一行@DYZ
-
我已经编辑了????
标签: regex python-3.x list iteration match