Answer the question
In order to leave comments, you need to log in
How to parse logs per minute?
There is an events.txt file like:
[2018-05-17 01:55:52.665804] NOK
[2018-05-17 01:56:23.665804] OK
[2018-05-17 01:56:55.665804] OK
[2018-05-17 01:57:16.665804] NOK
[2018-05-17 01:57:58.665804] OK
...
[2018-05-17 01:57]
[2018-05-17 01:58]
file_name = 'events.txt'
minutes = 38
with open(file=file_name, mode='r', encoding='utf8') as file:
for line in file:
if 'NOK' in line:
if minutes == int(line[15:17]):
print(line)
minutes += 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question