Path: csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'subject:Python': 0.06; 'automate': 0.07; 'is"': 0.07; 'cursor': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'subject:files': 0.09; 'subject:script': 0.09; 'trailing': 0.09; 'python': 0.11; 'language.': 0.14; 'posted': 0.15; '.txt': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recorded': 0.16; 'subject:txt': 0.16; 'the"': 0.16; 'files.': 0.16; 'folder': 0.16; 'language': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'foundation': 0.20; 'select': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'script.': 0.24; 'file.': 0.24; 'script': 0.25; 'query': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'characters': 0.30; 'lines': 0.31; 'subject:that': 0.31; 'txt': 0.31; 'file': 0.32; 'figure': 0.32; 'option': 0.32; 'run': 0.32; 'text': 0.33; 'open': 0.33; 'up.': 0.33; 'problem': 0.35; 'there': 0.35; 'done': 0.36; "i'll": 0.36; 'step': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'does': 0.39; 'delete': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'space': 0.40; 'remove': 0.60; 'blank': 0.60; 'cheque': 0.60; 'kindly': 0.61; 'you.': 0.62; 'save': 0.62; 'our': 0.64; 'charset:windows-1252': 0.65; 'reply': 0.66; 'containing': 0.69; '"contact': 0.84; '10:': 0.84; '11:': 0.84; '12:': 0.84; '13:': 0.84; '14:': 0.84; 'air,': 0.84; 'received:2': 0.84; 'subject:find': 0.84; 'syed': 0.84; 'opens': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Python script that does batch find and replace in txt files Date: Sun, 09 Nov 2014 20:17:54 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: host-2-98-204-224.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415564293 news.xs4all.nl 2858 [2001:888:2000:d::a6]:33645 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80439 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 start of file and Search for "Contact's Name:". Delete all the rows before it. > Step 2: Put cursor at end of file, Search for "Contact's Name:" select option UP. > Step 3: Search for "Photo of the" Replace with blanks > Step 4: Search for "Contact is" Replace with blanks > Step 5: Search for "Contact's Name:" Replace with blanks > Step 6: Search for "Age:" Replace with blanks > Step 7: Search for "Sex:" Replace with blanks > Step 8: Search for "House No:" Replace with blanks > Step 9: Search for "available" Replace with blanks > Step 10: Remove Empty Lines Containing Blank Characters from file > Step 11: Trim Leading Space for each line > Step 12: Trim Trailing Space after each line > Step 13: Search for - (hyphen) Replace with _ (underscore) > Step 14: Save file. > > Currently I have recorded a macro in Notepad++. > I open each file, run macro and save file. > As there are many files I was looking for a program to automate the process. > > I posted the same query in Notepad++ forum. I got a reply that it can be done by using Python script. > > Kindly do the needful. > > Thank you. > khalidness > No problem once your cheque made payable to the Python Software Foundation has been cashed. I'll pluck a figure of £200 out of the air, YMMV. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence