#!/bin/awk # Awk script to assign unique serial atom names to MOL2 files BEGIN { ATOMSECTION="FALSE" } { if ( $0 ~ /@BOND/ ) { ATOMSECTION="FALSE" } if ( ATOMSECTION=="TRUE" && $2 ~ /[A..Z]*[a..z]*/ ) { atomname=$2; # If this is the first time seeing "atomname", set count to 1 if ( !(atomname in atomcount) ) { atomcount[atomname] = 1; } # Create new atom name by concatenating atom name and number, e.g. C4 or S1 $2 = (atomname atomcount[atomname]) ++atomcount[atomname]; printf("%2i %3s % 8.5f % 8.5f % 8.5f %3s \n", $1, $2, $3, $4, $5, $6) } else { print $0 } if ( $0 ~ /@ATOM/ ) { ATOMSECTION="TRUE" } }