The code is :
`with open("tmp/"+filename.stem+".txt", "r") as infile:
readfile = infile.readlines()
with open("test/"+filename.stem+".txt", "w") as outfile:
for i, line in enumerate(line for line in readfile if 'M32' in line):
if '%' in readfile[i - 1]:
outfile.write(readfile[i - 6] + '\n')
outfile.write(readfile[i - 3] + '\n')
outfile.write(readfile[i - 1] + '\n')
print(i-1)
print(readfile[i-6])
print(readfile[i-3])
print(readfile[i-1])
else:
outfile.write(readfile[i - 3] + '\n')`
`with open("tmp/"+filename.stem+".txt", "r") as infile:
readfile = infile.readlines()
with open("test/"+filename.stem+".txt", "w") as outfile:
for i, line in enumerate(line for line in readfile if 'M32' in line):
if '%' in readfile[i - 1]:
outfile.write(readfile[i - 6] + '\n')
outfile.write(readfile[i - 3] + '\n')
outfile.write(readfile[i - 1] + '\n')
print(i-1)
print(readfile[i-6])
print(readfile[i-3])
print(readfile[i-1])
else:
outfile.write(readfile[i - 3] + '\n')`