Re: Delete lines which contain string in a file

2009-02-19 Thread Chris
On Feb 19, 12:24 am, Steve Holden wrote: > Rudi Goldman wrote: > > Hi, > > Go easy on me as I am a new to Python and am trying to solve a practical > > problem that is driving me bananas. > > Basically I have 2 text files, a source and a target. I want to be able > > to delete all of the lines in

Re: Delete lines which contain string in a file

2009-02-18 Thread Steve Holden
Rudi Goldman wrote: > Hi, > Go easy on me as I am a new to Python and am trying to solve a practical > problem that is driving me bananas. > Basically I have 2 text files, a source and a target. I want to be able > to delete all of the lines in the target file which contain text from > any line in

Delete lines which contain string in a file

2009-02-18 Thread Rudi Goldman
Hi, Go easy on me as I am a new to Python and am trying to solve a practical problem that is driving me bananas. Basically I have 2 text files, a source and a target. I want to be able to delete all of the lines in the target file which contain text from any line in the source file. i.e. Source:

Re: delete lines

2008-07-09 Thread Peter Otten
antar2 wrote: > I am new in python and I have the following problem: > > Suppose I have a list with words of which I want to remove each time > the words in the lines below item1 and above item2: > f = re.compile("item\[1\]\:") > g = re.compile("item\[2\]\:") > for i, line in enumerate(list1): >

delete lines

2008-07-09 Thread antar2
I am new in python and I have the following problem: Suppose I have a list with words of which I want to remove each time the words in the lines below item1 and above item2: item1 a b item2 c d item3 e f item4 g h item1 i j item2 k l item3 m n item4 o p I did not find out how to do this: Part o

Re: Delete lines containing a specific word

2008-01-07 Thread mik3l3374
On Jan 7, 1:21 am, Francesco Pietra <[EMAIL PROTECTED]> wrote: > Please, how to adapt the following script (to delete blank lines) to delete > lines containing a specific word, or words? > > f=open("output.pdb", "r") > for line in f: >

Re: Delete lines containing a specific word

2008-01-06 Thread sj26
Francesco Pietra wrote: > > Please, how to adapt the following script (to delete blank lines) to > delete > lines containing a specific word, or words? > > f=open("output.pdb", "r") > for line in f: > line=line.rstrip() > if line:

Re: Delete lines containing a specific word

2008-01-06 Thread Francesco Pietra
As I said I am no expert in OS and commands, except on what concerns mechanical statistical and quantum mechanical calculations. Therefore, better for me (and for all guys here) if I stop on this matter. My reply is only to say that I did the job with: f=open("prod1-3_no_wat_pop.pdb", "r") for lin

Re: Delete lines containing a specific word

2008-01-06 Thread Francesco Pietra
; > > >> On Sun, 06 Jan 2008 09:21:33 -0800, Francesco Pietra wrote: > >> > >> > Please, how to adapt the following script (to delete blank lines) to > >> > delete lines containing a specific word, or words? > >> > >> That's tricky,

Re: Delete lines containing a specific word

2008-01-06 Thread Steven D'Aprano
On Mon, 07 Jan 2008 00:42:01 +, Grant Edwards wrote: >> If you want to delete them, you still have to do the rest of the job >> yourself. > > Nonsense. > > How is this not doing what the OP asks? > >grep -v pattern infile >outfile; mv outfile infile It isn't deleting lines. As abstract

Re: Delete lines containing a specific word

2008-01-06 Thread Steven D'Aprano
On Mon, 07 Jan 2008 00:33:36 +0100, Bjoern Schliessmann wrote: > Steven D'Aprano wrote: > >> grep doesn't delete lines. grep matches lines. If you want to delete >> them, you still have to do the rest of the job yourself. > > In which way does "grep -v my

Re: Delete lines containing a specific word

2008-01-06 Thread Grant Edwards
gt;> >>> On Sun, 06 Jan 2008 09:21:33 -0800, Francesco Pietra wrote: >>> >>> > Please, how to adapt the following script (to delete blank lines) to >>> > delete lines containing a specific word, or words? >>> >>> That's tricky,

Re: Delete lines containing a specific word

2008-01-06 Thread bukzor
On Jan 6, 3:33 pm, Bjoern Schliessmann wrote: > Steven D'Aprano wrote: > > grep doesn't delete lines. grep matches lines. If you want to > > delete them, you still have to do the rest of the job yourself. > > In which way does "grep -v mypattern myfile >

Re: Delete lines containing a specific word

2008-01-06 Thread Bjoern Schliessmann
Steven D'Aprano wrote: > grep doesn't delete lines. grep matches lines. If you want to > delete them, you still have to do the rest of the job yourself. In which way does "grep -v mypattern myfile > myfile" not delete the lines matching mypattern? Regards, Björn

Re: Delete lines containing a specific word

2008-01-06 Thread Steven D'Aprano
; Please, how to adapt the following script (to delete blank lines) to >> > delete lines containing a specific word, or words? >> >> That's tricky, because deleting lines from a file isn't a simple >> operation. No operating system I know of (Windows, Linux,

Re: Delete lines containing a specific word

2008-01-06 Thread Martin Marcher
On Sunday 06 January 2008 21:25 Francesco Pietra wrote: >> yes lines starting with a "#" are comments in python but that shouldn't >> be of concern for your input data. I don't quite get what you want >> here... > > Leaving the lines commented out would permit to resume them or at least > remeber

Re: Delete lines containing a specific word

2008-01-06 Thread Francesco Pietra
Steven: Thanks. See below please (of very marginal interest) --- Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 06 Jan 2008 09:21:33 -0800, Francesco Pietra wrote: > > > Please, how to adapt the following script (to delete blank lines) to > > delete lines c

Re: Delete lines containing a specific word

2008-01-06 Thread Steven D'Aprano
On Sun, 06 Jan 2008 09:21:33 -0800, Francesco Pietra wrote: > Please, how to adapt the following script (to delete blank lines) to > delete lines containing a specific word, or words? That's tricky, because deleting lines from a file isn't a simple operation. No operating

Re: Delete lines containing a specific word

2008-01-06 Thread Francesco Pietra
--- Martin Marcher <[EMAIL PROTECTED]> wrote: > On Sunday 06 January 2008 18:21 Francesco Pietra wrote: > > > Please, how to adapt the following script (to delete blank lines) to > > delete lines containing a specific word, or words? > > > > f=open(

Re: Delete lines containing a specific word

2008-01-06 Thread Martin Marcher
On Sunday 06 January 2008 18:21 Francesco Pietra wrote: > Please, how to adapt the following script (to delete blank lines) to > delete lines containing a specific word, or words? > > f=open("output.pdb", "r") > for line in f: > line=line.rstrip() > if l

Re: Delete lines containing a specific word

2008-01-06 Thread Grant Edwards
On 2008-01-06, Matt Nordhoff <[EMAIL PROTECTED]> wrote: >> Please, how to adapt the following script (to delete blank lines) to delete >> lines containing a specific word, or words? > If you're on Linux, why not just use grep? > > $ grep -v theword output.pdb A

Fwd: Delete lines containing a specific word

2008-01-06 Thread Francesco Pietra
) > From: Francesco Pietra <[EMAIL PROTECTED]> > Subject: Delete lines containing a specific word > To: python-list@python.org > > Please, how to adapt the following script (to delete blank lines) to delete > lines containing a specific word, or words? > > f=open("out

Re: Delete lines containing a specific word

2008-01-06 Thread Matt Nordhoff
Francesco Pietra wrote: > Please, how to adapt the following script (to delete blank lines) to delete > lines containing a specific word, or words? > > f=open("output.pdb", "r") > for line in f: > line=line.rstrip() > if line: >

Delete lines containing a specific word

2008-01-06 Thread Francesco Pietra
Please, how to adapt the following script (to delete blank lines) to delete lines containing a specific word, or words? f=open("output.pdb", "r") for line in f: line=line.rstrip() if line: print line f.close() If python in Linux accepts lines