On Fri, Jan 12, 2001 at 10:46:36AM -0800, Kenward Vaughan wrote: ... Though you ask for a sh script, this problem is easily solved with a higher level scripting language like Perl or Python. As I can't get my mind to grog Perl, I'll go ahead with Python:
#/usr/bin/python # expected use cleanup hup.m3d hup.pdb # to replace 'Du' with "O " inline. # MIND YOU, THIS IS UNTESTED CODE, SO TAKE CARE AND BACKUP FIRST import sys, fileinput name = sys.argv[1] ### Input files: <name>.m3d output files: <name>.pdb ### In each file, individual atoms take up a line each. # let us start by reading the input file # and store it internally as a list of lines m3d = open(name+".pdb").readlines() # the second file is input and output, so we use a smart Python module # to easy coping with this. A backup is created and changes made to lines # can be preserved in the file simply by writing to stdout. pdb = fileinput.input(name+".pdb", inplace=1, backup=1) ### The list of atoms in the input file always start on the 3rd line, and the # so let's get rid ot those first 2 lines m3d = m3d[2:] ### labels cover columns 7 and 8 (one or two letters/symbol, space if no 2nd ### letter). I have yet to see an improperly constructed file. # let's get rid of all unneeded chars m3d = map(lambda x: x[6,8], m3d) ### The list begins on line 3 in the output file, with symbols in col. 14,15. # ^? but the example shows 3 leading lines! # anyway, let's save those lines firs?t while pdb.filelineno()!=3: #or 2???? sys.stdout(pdb.readline()) ### This format is definitely consistent, coming out of the converter app. ### ### Other lines follow the list in both files. So... ### input file: output file: ### .......... ........ ### .......... ........ ### ......O .... ........ ### ......H .... ATOM.........Du.... <-- needs to change to "O " ### ......H .... ATOM.........H .... ### ........ ATOM.........H .... ### ......... for atom in m3d: line = pdb.readline() if line[13:15] == "Du": line[13:15] = m3d sys.stdout(line) -- groetjes, carel