I am searching far a particular string using this code:
stringToMatch = 'blah'
matchedLine = ''
#get line
with open(r'path of the text file', 'r') as file:
for line in file:
if stringToMatch in line:
matchedLine = line
break
#and write it to the file
with open(r'path of the text file ', 'w') as file:
file.write(matchedLine)
This prints only the string once even if it occurs multiple times. I also want to print all the lines after a particular word occurs. How do i do that?
breaksays leave thefor looponce it found one case. You may need to remove/modify that.