When processing the input, the first character in the first list is replaced with the first character in the second list, the second character in the first list is replaced with the second character in the second list, and so on. Some time ago, a user proposed to us that we add a transliteration function to gawk . This program is not as complete as the system tr utility, but it will do most of the job. There are two functions. The first, stranslate , takes three arguments. from A list of characters to translate from.
Associative arrays make the translation part fairly easy.
Then a simple loop goes through from , one character at a time. For each character in from , if the character appears in target , gsub is used to change it to the corresponding to character. The main program sets two global variables, FROM and TO , from the command line, and then changes ARGV so that awk will read from the standard input. Finally, the processing rule simply calls translate for each record. However, shortly after writing this program, we learned that the System V Release 4 awk had added the toupper and tolower functions.