I have example text file of more that 35000 line in which there is a pattern like, how to write python code to extract data between two lines.
Violator was running
MaxSelect
Modified by Violator
some lines
some more lines
Violator was running
Code
fixed
Modified by Violator
I want to read the file and extract the data between Violator was running and Modified by Violator along with the line code and write these data to new output.txt file. I have the same string pattern of Violator throughout the text file just want to extract the data between them. Please help.
with open('example.txt', 'r') as rf:
output = rf.readlines()
s = len(output) - 1
gen ="Violator was running"
show = "Modified by Violator"
for count, line in enumerate(rf,start=1):
if re.match(gen, line) and re.match(show):
print(rf.readlines())
This is what I haved tried