Copyright (C) 2000-2012 |
GNU Info (textutils.info)TranslatingTranslating ----------- `tr' performs translation when SET1 and SET2 are both given and the `--delete' (`-d') option is not given. `tr' translates each character of its input that is in SET1 to the corresponding character in SET2. Characters not in SET1 are passed through unchanged. When a character appears more than once in SET1 and the corresponding characters in SET2 are not all the same, only the final one is used. For example, these two commands are equivalent: tr aaa xyz tr a z A common use of `tr' is to convert lowercase characters to uppercase. This can be done in many ways. Here are three of them: tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ tr a-z A-Z tr '[:lower:]' '[:upper:]' When `tr' is performing translation, SET1 and SET2 typically have the same length. If SET1 is shorter than SET2, the extra characters at the end of SET2 are ignored. On the other hand, making SET1 longer than SET2 is not portable; POSIX.2 says that the result is undefined. In this situation, BSD `tr' pads SET2 to the length of SET1 by repeating the last character of SET2 as many times as necessary. System V `tr' truncates SET1 to the length of SET2. By default, GNU `tr' handles this case like BSD `tr'. When the `--truncate-set1' (`-t') option is given, GNU `tr' handles this case like the System V `tr' instead. This option is ignored for operations other than translation. Acting like System V `tr' in this case breaks the relatively common BSD idiom: tr -cs A-Za-z0-9 '\012' because it converts only zero bytes (the first element in the complement of SET1), rather than all non-alphanumerics, to newlines. automatically generated by info2www version 1.2.2.9 |