471,330 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

Strip lines from files

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=Ahu06i...Dypao8Wcj9tAcJ

Jan 8 '08 #1
1 2953
Francesco Pietra wrote:
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
Jan 10 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by qwweeeit | last post: by
16 posts views Thread by Voetleuce en f?nsievry | last post: by
3 posts views Thread by Michal A. Valasek | last post: by
1 post views Thread by KevinGPO | last post: by
5 posts views Thread by micklee74 | last post: by
6 posts views Thread by aiwarrior | last post: by
7 posts views Thread by Nick | last post: by
1 post views Thread by Mel | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.