Here are the options:
a-b
means a range of characters from
a
to b
in increasing ASCII order. Customary Perl escapes are honored, such as \n
for newline, \012
for octal, and \x0A
for hexadecimal codes.
If the -c flag is specified, the SEARCHLIST character set is complemented. If the -d flag is specified, any characters specified by SEARCHLIST not found in REPLACEMENTLIST are deleted. (Note that this is slightly more flexible than the behavior of some tr programs, which delete anything they find in the SEARCHLIST, period.) If the -s flag is specified, sequences of characters that were transliterated to the same character are squashed down to a single instance of the character.
If the -d flag is used, the REPLACEMENTLIST is always interpreted exactly as specified. Otherwise, if the REPLACEMENTLIST is shorter than the SEARCHLIST, the final character is replicated till it is long enough. If the REPLACEMENTLIST is empty, the SEARCHLIST is replicated. This latter is useful for counting characters in a class or for squashing character sequences in a class.
The first -U or -C flag applies to the left side of the translation. The second one applies to the right side. If present, these flags override the current utf8 state.
tr -cs A-Za-z "\n" <file1 >file2
The following command strips the 8th bit from an input file:
tr "\200-\377" "\000-\177"
The following command translates Latin-1 to Unicode:
tr -CU "\0-\xFF" ""
The following command translates Unicode to Latin-1
tr -UC "\0-\x{FF}" ""
tr
operator. See the documentation in perlop for details on its operation.
Not all systems have Unicode support yet, in which case the -U or -C flags would cause a fatal error.
This program is free and open software. You may use, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same.