python 截取某一天的日志,简单操作

时间:2023-03-08 17:08:32
#!/usr/bin/python
#Filename: Segmentation_log.py import re,sys def openfile(*args):
try:
f=open(args[0],'r')
try:
while True:
lines = f.readlines(100)
if not lines:
break
for line in lines:
if(line.find(args[1])>=0):
writenewfile(line,args[2])
finally:
f.close()
print '*'*21+"END"+"*"*21
except IOError:
print args[0]+" not find!" def writenewfile(*args):
try:
newfile=open(args[1],'a')
try:
newfile.write(args[0])
finally:
newfile.close() except IOError:
print args[1]+"not find!!" def chuli(*args):
print '*'*20+"START"+"*"*20
logre=re.split('\.',args[0])
newlogfile=logre[0]+args[1]+"."+logre[1]
openfile(args[0],args[1],newlogfile) if __name__=='__main__':
chuli(sys.argv[1],sys.argv[2])

有一客户发过来一个日志,谁知道太大了, 打不开,打开了,编辑器操作也很慢,好吧,自己动手.