On Fri, Jan 12, 2001 at 10:46:36AM -0800, Kenward Vaughan wrote: > Hi, > > I have written about 5 successful low-level scripts to do various things, > and want to learn more about the ways, but I'm in a time crunch (classes > are starting next week) and I can't begin to grok what's needed for this. > I was hoping some kind, (bored?) soul could throw clues this way.. ?? :)
well, whatever I am (kind, bored, ... :), here is another one in Perl for you to compare with the Python solution already posted: #!/usr/bin/perl -i.bak # if you don't want backup files, use just '-i' instead while (<>) { # for each line in the output file... if ($outfile ne $ARGV) { # make this 'if' match only once (at the beginning of each file) $infile = $outfile = $ARGV; # '.pdb' -> '.m3d' for input filename $infile =~ s/pdb$/m3d/; # open associated input file open IN, $infile or die "Cannot open file '$infile'!\n"; $line = 1; } $in = <IN>; if (/^ATOM/) { # extract symbols $isym = substr($in, 6, 2); $osym = substr($_, 13, 2); if ($osym eq 'Du') { # replace out-symbol with symbol from infile substr($_, 13, 2) = $isym; } elsif ($isym ne $osym) { # verify the assumption that symbols match if out-symbol is not 'Du' print STDERR "Warning: symbols don't match! ($ARGV:$line: '$osym'/'$isym')\n"; } } print $_; # write out $line++; # (line counter for warning msg) } The script assumes that you have the same number of leading lines in both files, as you described (input: '3rd line', output: 'line 3'). In your sketch of the file contents, however, it looks as if there is one more leading line in the output file. If that's not just a typo, you'd have to make a small change to the script to make corresponding rows align. Let me know if you can't figure it out yourself... Call it like this: script <list of .pdb-files to change> e.g. script *.pdb (where 'script' is the name you choose, of course) Corresponding input files are assumed to reside in the same directory. Original output files will be renamed to '*.pdb.bak'. Enjoy, Erdmut -- Bugs come in through open windows. Keep Windows shut! --