Am trying to write a python script to search and replace this line:
time residue 3 Total
with an empty line.
This is my script:
import glob
read_files = glob.glob("*.agr")
with open("out.txt", "w") as outfile:
for f in read_files:
with open(f, "r") as infile:
outfile.write(infile.read())
with open("out.txt", "r") as file:
filedata = file.read()
filedata = filedata.replace(r'#time\s+residue\s+[0-9]\s+Total', 'x')
with open("out.txt", "w") as file:
file.write(filedata)
Using this, am not able to get any replacement. Why could that be? The rest of the code is working fine. The output file has not change to it so i suspect that the pattern cant be found.
Thank you.