I would like to copy certain lines of text from one text file to another. In my current script when I search for a string it copies everything afterwards, how can I copy jus
with open("list1.txt") as f:
doIHaveToCopyTheLine = False
'''open output file in write mode'''
with open("output.txt", 'w') as f1:
'''iterate line by line'''
for line in f:
if 'tests/file/myword' in line:
doIHaveToCopyTheLine = True
elif doIHaveToCopyTheLine:
f1.write(line)