Python script that does batch find and replace in txt files

Syed Khalid khalidness at
Sun Nov 9 22:08:13 CET 2014

My Script, 

I have added 

import glob, codecs, re, os

regex = re.compile(r"Age: |Sex: |House No: ") # etc etc
Script I executed in EditRocket :

for txt in glob.glob("/D:/Python/source/*.txt"):   
    with, encoding="utf-8") as f:
        oldlines = f.readlines()
    for i, line in enumerate(oldlines):
        if "Contact's Name:" in line:
    newlines = [regex.sub("", line).strip().replace("-", "_") for line in oldlines[i:]
    with + "_out.txt", "wb", encoding="utf-8") as w:

Error Message :

  File "EamClean.log", line 12
    with + "_out.txt", "wb", encoding="utf-8") as w:
SyntaxError: invalid syntax

Kindly do the needful

More information about the Python-list mailing list