BEGIN {FS = " " } { END_match = match($0,"LIG 0") TRI_match = match($0,"TRIPOS>MOLECULE") LIG_match = match($0,"LIGAND") if (END_match == 0) { if (LIG_match != 60) { if (TRI_match == 3) { getline name = $1 short_nam = substr(name,3,2) printf("%s\n","@MOLECULE") } else { printf("%s\n",$0) } } else { split ($0,first,"LIGAND") printf("%s\t%s\t%s\n",first[1],short_nam,first[2]) } } else { split ($0,last,"LIGAND") printf("%s\t%s\t%s\n",last[1],short_nam,last[2]) short_nam = " " } }