Delete lines which contain string in a file

Chris cwitts at gmail.com
Thu Feb 19 03:12:12 EST 2009


On Feb 19, 12:24 am, Steve Holden <st... at holdenweb.com> 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 the target file which contain text from
> > any line in the source file.
> > i.e.
> > Source:                                     Target:
> > 111                                           xxx 111 yyy  
> > 222                                           xxx  333 sss
> > 333                                           jjj   444 sss
>
> > After executing this code the target file should only consist of the
> > line:     jjj   444 sss
> > Any help on this one would be greatly appreciated.
>
> Is this homework?
>
> How far have you got with your design?
>
> regards
>  Steve
> --
> Steve Holden        +1 571 484 6266   +1 800 494 3119
> Holden Web LLC              http://www.holdenweb.com/

Who needs python for this...

cwitts at cwitts-mint ~ $ cat src.txt
[111,222,333]
cwitts at cwitts-mint ~ $ cat tgt.txt
xxx 111 yyy
xxx  333 sss
jjj   444 sss
cwitts at cwitts-mint ~ $ grep -v -f src.txt tgt.txt
jjj   444 sss



More information about the Python-list mailing list