以14分钟完成了对23G日志文件的检索:
#!/usr/bin/env python
#coding=utf-8import re
import time
results = open('/tmp/results.txt','a+')
start_time = 'Starting searching at %s' %time.strftime('%Y-%m-%d %H:%M:%S')
results.write(start_time + '\n')
carp = re.compile('snat.*57056')
with open('/syslogs/log-rotate/messages-2016081519','r') as logging:
for i in logging:
if carp.search(i):
results.write(i + '\n')
end_time = 'Finish searching at %s' %time.strftime('%Y-%m-%d %H:%M:%S')
results.write(end_time + '\n')results.close()