[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 6:50:00 AM


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

> On Sun, 06 Jan 2008 13:33:52 -0800, Francesco Pietra wrote:
>
> > Steven:
> > Thanks. See below please (of very marginal interest)
> >
> > --- Steven D'Aprano <steven@REMOVE.THIS.cybersource.com.au> 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 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, OS X) has a
> >> "delete line" function.
> >
> > As I am at Debian Linux, I do that with grep -v
>
> 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.

Well, I use Debian Linux for scientific purposes, so that I have no much time
toget expertise even in the OS. Though, from the command (as user)

grep -v theword thefile.pdb

I get thefile.pdb without the lines containing "theword".

>
>
> >> Secondly, you might want the script to write its output to a file,
> >> instead of printing. So, instead of the line "print line", you want it
> >> to write to a file.
> >
> > may be cumbersome, though I use 2>&1 | tee output file.pdb so that I
> > can see what happens on the screen and have the modified file.
>
> Yes, matching lines and sending them to stdout is a better solution than
> trying to delete them from a file.
>
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/p...
>



____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypa...