I am writing a code in Python for searching a string in a huge text file which will occur every 10-15 lines and copying its next line in another text file. I am a beginner in Python so not sure what would be best to do this. I am trying by using the below script:
name = raw_input('Enter file:') with open(name) as f: with open("output.txt", "w") as f1: for line in f: if "IDENTIFIER" in line: f1.write(line)
After this what I need in output file is the entire next line after this string is found.
something like line+1 which I suppose is not available in Python.
How can I jump to the next line and write that line in the output file after me text IDENTIFIER?
with open("file_in.txt") as f: with open("file_out.txt","w") as f2: for line in f: if "my_test" in line: f2.write(line.rstrip("\n")+next(f)) # the next line :P