Delete lines containing a specific word

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Sun Jan 6 22:42:11 EST 2008


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
> lines matching mypattern?

Okay, that will delete the lines matching mypattern. Unfortunately it 
will also delete all the lines NOT matching mypattern as well. Try it for 
yourself -- just not on anything you care about.

This is what happens when abstractions leak. You *think* you're deleting 
lines, but you're not. That's just an abstraction, and when it leaks, you 
break things.



-- 
Steven



More information about the Python-list mailing list