python 日志内容提取


 

问题:如下,一个很大的日志文件,提取 start: 到 end: 标志中间的内容

日志文件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

输出

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

 

参考:

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM