[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Delete lines containing a specific word

Francesco Pietra

1/7/2008 7:00:00 AM

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 line in f:
line=line.rstrip()
if "WAT" not in line:
print line
f.close()

It took time on the billion lines to write, though it worked. About grep may be
you are right. At any event, in my job I never edit a file without saving a
separate copy of the original. Think that I'll never carry out a computation
(that may last weeks) without a raid 1 system. Not to mention certain
commercial OS that are carefully avoided for calculations (in my office for
everything), also because they need to emulate unix to do that.

cheers
francesco
--- Steven D'Aprano <steven@REMOVE.THIS.cybersource.com.au> wrote:

> On Mon, 07 Jan 2008 00:42:01 +0000, 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 abstractions go, it comes pretty close, but
> just try it on a disk with insufficient free space for the temporary
> outfile and watch it break.
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/p...
>



____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?categor...