# Generate the list of headwords from the lexicon file. function CleanUp() #Clean up for next input record. { for (i in rec) delete rec[i]; } BEGIN{ RS = ""; FS = "\n?%"; } { # Create an associative array with the tags as indices. # The leading FS creates an initial empty field for(i = 2; i <= NF; i++){ split($i, f,"\ "); #Split field on space to separate tag from content #f[1] now contains the tag. rec[f[1]]=substr($i,index($i,"\ ")+1);#The content is the part of the field following the } #the spaces after the tag. We can't just use f[2] printf("%s\n", rec["head"]); #because the content may have other spaces in it CleanUp(); #so f[2] may not be the entire content. }