Extract the contents of the log python

 

Problem: the following, a lot of log files, extract the start: to end: sign in the middle of contents

Log Files a.log

xxxxx
yyyyy
start:
start:
hahahaha
end:
start:
hahahahha
end:
ccccccc
kkkkkkk
cdcdcdcd
start:
hahahaha
end:

 

code

import re

isfind=False
with open("a.log","r") as f:
    while(1):
        l=f.readline()
        if(not l):
            break
        if(re.match("start:", l)):
            isfind=True
        if(isfind):
            print(l)
            if(re.match("end:", l)):
                isfind=False

Export

start:
start:
hahahaha
end:
start:
hahahahha
end:
start:
hahahaha
end:

 

reference:

https://www.cnblogs.com/aaronthon/p/9435967.html

 

Guess you like

Origin www.cnblogs.com/sea-stream/p/11246484.html