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.
Expand|Select|Wrap|Line Numbers
- 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_code.txt ):
Expected output is ( Expected_output.txt ):
Pls help me here to do it in best way