Lets say I have a Text file (input_file.txt , file size is ~10GB ).
Now I need to write a Python code which will read the text file and copy the contents between Start and end to another file.
I wrote the following code.
I'm not getting the desired output as expected:
Output of the code ( output_of_my_co de.txt ):
Expected output is ( Expected_output .txt ):
Pls help me here to do it in best way
Now I need to write a Python code which will read the text file and copy the contents between Start and end to another file.
I wrote the following code.
Code:
import re with open(r'C:\Python27\log\master_input.txt', 'r') as infile, open(r'C:\Python27\log\output', 'w') as outfile: copy = False for line in infile: if re.match("Jun 6 17:58:16(.*)", line): copy = True elif re.match("Jun 6 17:58:31(.*)", line): copy = False elif copy: outfile.write(line)
Output of the code ( output_of_my_co de.txt ):
Expected output is ( Expected_output .txt ):
Pls help me here to do it in best way
Comment