我有一个1000行的文件,在那里我需要找到一个匹配的模式,一旦我找到了,需要找到下一个匹配的模式,从那里开始,而不是从一开始
示例:
match1= Unlock event detected
match2= presence service not connected
.....
.....
10:12:53,presence service not connected
.....
.....
11:12:53, Unlock event detected ----> Matching pattern
.....
.....
11:13:53, presence service not connected ----> next matching pattern
.....
.....
我需要11:12:53和11:13:53而不是10:12:53
# Collect the list of hits
list_log = []
# opening the file
with open (file,'r', errors='ignore') as f:
lines = f.read().splitlines()
#for loop and find the matching pattern
for l in lines:
if re.findall(r"Unlock event detected", l):
list_log.append(l)
elif re.findall(r'presence service not connected',l):
list_log.append(l)
for ll in list_log:
print(ll)
要进入list\u log,只需在登录时添加附加条件即可
输出(将数据用作文件)
相关问题 更多 >
编程相关推荐