#!/bin/sh awk ' # load acronyms file into array "acro" FILENAME == "acronyms" { split($0,entry,"\t") acro[entry[1]]=entry[2] next } # read any input line containing caps $0 ~ /[A-Z][A-Z]+/ { # loop through acronyms for ( acronym in acro ) { # compare each field to acronym newnf = NF for (i = 1; i <= NF; i++) if ( $i == acronym ) { # debug line -- print "NF before:", NF # if it matches, add description $i = acro[acronym] " (" $i ")" newnf += split(acro[acronym],dummy) # debug line -- print "NF after:", NF } NF = newnf } } { # print all lines print $0 }' acronyms $* # # #Comments by G Wildenberg: # #What I like about this one is the overall structure. When this program is #called as a shell script, the file names to process are in $*, #but since the call to awk is really of the form: #awk 'big-awk-program-in-quotes-above' acronyms $* , #then acronyms is loaded first and treated in a special way. #