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

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 > 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
; 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