Delete lines containing a specific word

Francesco Pietra chiendarret at yahoo.com
Mon Jan 7 02:00:14 EST 2008


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 at 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/python-list
> 



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



More information about the Python-list mailing list