Re: Python script that does batch find and replace in txt files

2014-11-11 Thread Denis McMahon
On Sun, 09 Nov 2014 11:58:49 -0800, Syed Khalid wrote: > Python script that does batch find and replace in txt files Need a > python script that opens all .txt files in a folder find replace/delete > text and save files. Sounds like you need sed, not python. -- Denis McMahon, de

RE: Python script that does batch find and replace in txt files

2014-11-11 Thread Clayton Kirkwood
>-Original Message- >From: Python-list [mailto:python-list- >bounces+crk=godblessthe...@python.org] On Behalf Of Syed Khalid >Sent: Sunday, November 09, 2014 1:08 PM >To: python-list@python.org >Subject: Re: Python script that does batch find and replace in txt files

Re: Python script that does batch find and replace in txt files

2014-11-10 Thread alister
On Sun, 09 Nov 2014 17:49:29 -0800, Syed Khalid wrote: > Albert, > > Code is not removing empty lines containing blank characters and not > removing leading and trailing spaces present in each line. > > > > > import glob, codecs, re, os > > regex = re.compile(r"Age: |Sex: |House No: ") # e

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Albert, Code is not removing empty lines containing blank characters and not removing leading and trailing spaces present in each line. import glob, codecs, re, os regex = re.compile(r"Age: |Sex: |House No: ") # etc etc for txt in glob.glob("D:/Python/source/*.txt"): with codecs.o

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Albert-Jan Roskam
On Sun, Nov 9, 2014 10:51 PM CET Syed Khalid wrote: >Albert, > >Thanks a million for script, > >It worked fine after I closed the bracket. > > >import glob, codecs, re, os > >regex = re.compile(r"Age: |Sex: |House No: ") # etc etc > >for txt in glob.glob("D:/Python/s

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
"EamClean.log", line 12 >> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w: >>^ >> SyntaxError: invalid syntax >> >> Kindly do the needful. >> >> On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread MRAB
On 2014-11-09 21:20, Syed Khalid wrote: Code after adding path of .txt files : import glob, codecs, re, os regex = re.compile(r"Age: |Sex: |House No: ") # etc etc for txt in glob.glob("D:/Python/source/*.txt"): with codecs.open(txt, encoding="utf-8") as f: oldlines = f.readlines

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
^ > SyntaxError: invalid syntax > > Kindly do the needful. > > On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan Roskam > wrote: > >> >> >> >> >> - Original Message - >> > From: Syed Khalid >> > To: python-list@python.org &g

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
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 codecs.open(txt, encoding="utf-8") as f: oldlines = f.readlines() for i, line

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
014 at 1:53 AM, Albert-Jan Roskam wrote: > > > > > - Original Message - > > From: Syed Khalid > > To: python-list@python.org > > Cc: > > Sent: Sunday, November 9, 2014 8:58 PM > > Subject: Python script that does batch find and replace in txt files >

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Albert-Jan Roskam
- Original Message - > From: Syed Khalid > To: python-list@python.org > Cc: > Sent: Sunday, November 9, 2014 8:58 PM > Subject: Python script that does batch find and replace in txt files > > Python script that does batch find and replace in txt files Need a pyt

Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Mark Lawrence
On 09/11/2014 19:58, Syed Khalid wrote: Python script that does batch find and replace in txt files Need a python script that opens all .txt files in a folder find replace/delete text and save files. I have text files and I need to perform below steps for each file. Step 1: Put cursor at

Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Python script that does batch find and replace in txt files Need a python script that opens all .txt files in a folder find replace/delete text and save files. I have text files and I need to perform below steps for each file. Step 1: Put cursor at start of file and Search for "Contact&#