Strip lines from files

  • Thread starter Francesco Pietra
  • Start date
F

Francesco Pietra

I am posting again as previous identical message had alleged suspicious header.

I used successfully script

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()

to strip lines containing the word WAT from a very long file.

A variant need has now emerged, to perform the same task from a very long
series of shorter files trp.pdb.1, trp.pdb.2 ,..... Could you see how to adapt
the above script to the new need?

Or adapt

grep -v WAT trp.pdb.1

grep -v WAT trp.pdb.2

.....................

grep -v WAT trp.pdb.n

Unless you can think better to remove that pervasive molecule of water, to
avoid performing the calculation ex novo.

Thanks

francesco pietra


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

Caleb

Francesco said:
I am posting again as previous identical message had alleged suspicious header.

I used successfully script

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()

log = [[line for line in file(filename,'r') if line.find('WAT')=-1] for
filename in filenamelist]
print log

You can populate filenamelist however you like, e.g. with a command-line
wildcard into sys.argv, or with a os.listdir lookup as in

filenamelist = [filename for filename in os.listdir('.') if
filename.find('.pdb.')]

Caleb
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top