Delete lines containing a specific word

mik3l3374 at gmail.com mik3l3374 at gmail.com
Mon Jan 7 07:43:55 EST 2008


On Jan 7, 1:21 am, Francesco Pietra <chiendar... at yahoo.com> wrote:
> Please, how to adapt the following script (to delete blank lines) to delete
> lines containing a specific word, or words?
>
> f=open("output.pdb", "r")
> for line in f:
>         line=line.rstrip()
>         if line:
>                 print line
> f.close()
>
> If python in Linux accepts lines beginning with # as comment lines, please also
> a script to comment lines containing a specific word, or words, and back, to
> remove #.
>
> Thanks
> francesco pietra
>
>       ____________________________________________________________________________________
> Looking for last minute shopping deals?
> Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping

for line in open("file"):
    if not "word" in line:
         print line


on the command, use the ">" operator to redirect to a file



More information about the Python-list mailing list