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

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): >

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: > line=line.rstrip() > if line: >

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: > print line > f.close() > > If pytho

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
--- Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 06 Jan 2008 13:33:52 -0800, Francesco Pietra wrote: > > > 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 Piet

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 mypattern myfile > myfile" not delete the >

Re: Delete lines containing a specific word

2008-01-06 Thread Grant Edwards
On 2008-01-06, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Sun, 06 Jan 2008 13:33:52 -0800, Francesco Pietra wrote: > >> 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 Pi

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 > myfile" not delete the > lines matching myp

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 -- BOFH excuse #184: loop fo

Re: Delete lines containing a specific word

2008-01-06 Thread Steven D'Aprano
On Sun, 06 Jan 2008 13:33:52 -0800, Francesco Pietra wrote: > 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

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 containing a specific word, or wor

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 system I know of (Windo

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("output.pdb", "r") > > for line in f: > > line

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 line: > print line > f.close() >>> import r

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 And if you're on Windows, install Cy

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: > print line > f.close() > > If python in Li