Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80439

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

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 <python-python-list@m.gmane.org>
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 <breamoreboy@yahoo.co.uk>
Subject Re: Python script that does batch find and replace in txt files
Date Sun, 09 Nov 2014 20:17:54 +0000
References <e9ee1f6f-9397-4dc5-a357-381ebc9b6e57@googlegroups.com>
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 <e9ee1f6f-9397-4dc5-a357-381ebc9b6e57@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15606.1415564293.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-09 11:58 -0800
  Re: Python script that does batch find and replace in txt files Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-09 20:17 +0000
  Re: Python script that does batch find and replace in txt files Albert-Jan Roskam <fomcl@yahoo.com> - 2014-11-09 20:23 +0000
  Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-10 02:22 +0530
    Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-09 13:08 -0800
      RE: Python script that does batch find and replace in txt files "Clayton Kirkwood" <crk@godblessthe.us> - 2014-11-09 15:03 -0800
  Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-10 02:50 +0530
  Re: Python script that does batch find and replace in txt files MRAB <python@mrabarnett.plus.com> - 2014-11-09 21:44 +0000
  Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-10 03:21 +0530
  Re: Python script that does batch find and replace in txt files Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-11 20:04 +0000

csiph-web