功能:主要用于日志关键字提取,并保存关键字附近行到文件中
import time
time_start=time.time()
info = "port"
old_line1 = " "
old_line2 = " "
old_line3 = " "
info = input("input you want to find:")
f = open("base.log","r")
fw = open("result.txt", "a+")
line = f.readline()
times = 1
line_number = 1
while line:
old_line3 = old_line2
old_line2 = old_line1
old_line1 = line
#print("new line:", line)
#
#print("old line:", old_line)
if line.find(info) >= 0:
#print("old_line3:", old_line3)
#print("old_line2:", old_line2)
#print("find the info:", line)
fw.write("***************************"+"\n")
fw.write("***********