1 .\" Copyright (c) 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" @(#)tr.1 8.1 (Berkeley) 6/6/93
43 .Nd translate characters
63 utility copies the standard input to the standard output with substitution
64 or deletion of selected characters.
66 The following options are available:
69 Complement the set of characters in
73 includes every character except for
80 but complement the set of values in
87 Squeeze multiple occurrences of the characters listed in the last
92 in the input into a single instance of the character.
93 This occurs after all deletion and translation is completed.
95 Guarantee that any output is unbuffered.
98 In the first synopsis form, the characters in
100 are translated into the characters in
102 where the first character in
104 is translated into the first character in
111 the last character found in
117 In the second synopsis form, the characters in
119 are deleted from the input.
121 In the third synopsis form, the characters in
123 are compressed as described for the
127 In the fourth synopsis form, the characters in
129 are deleted from the input, and the characters in
131 are compressed as described for the
135 The following conventions can be used in
139 to specify sets of characters:
140 .Bl -tag -width [:equiv:]
142 Any character not described by one of the following conventions
145 A backslash followed by 1, 2 or 3 octal digits represents a character
146 with that encoded value.
147 To follow an octal sequence with a digit as a character, left zero-pad
148 the octal sequence to the full 3 octal digits.
150 A backslash followed by certain special characters maps to special
154 .It "\ea <alert character>
158 .It "\er <carriage return>
160 .It "\ev <vertical tab>
163 A backslash followed by any other character maps to that character.
165 For non-octal range endpoints
166 represents the range of characters between the range endpoints, inclusive,
168 as defined by the collation sequence.
169 If either or both of the range endpoints are octal sequences, it
170 represents the range of specific coded values between the
171 range endpoints, inclusive.
176 section below for an important note regarding
177 differences in the way the current
178 implementation interprets range expressions differently from
179 previous implementations.
182 Represents all characters belonging to the defined character class.
185 .Bl -column "phonogram"
186 .It "alnum <alphanumeric characters>
187 .It "alpha <alphabetic characters>
188 .It "blank <whitespace characters>
189 .It "cntrl <control characters>
190 .It "digit <numeric characters>
191 .It "graph <graphic characters>
192 .It "ideogram <ideographic characters>
193 .It "lower <lower-case alphabetic characters>
194 .It "phonogram <phonographic characters>
195 .It "print <printable characters>
196 .It "punct <punctuation characters>
197 .It "rune <valid characters>
198 .It "space <space characters>
199 .It "special <special characters>
200 .It "upper <upper-case characters>
201 .It "xdigit <hexadecimal characters>
204 .\" All classes may be used in
212 .\" options are specified.
213 .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
215 .\" and then only when the corresponding class (``upper'' for ``lower''
216 .\" and vice-versa) is specified in the same relative position in
225 appears in the same relative position in
227 it represents the characters pairs from the
231 category of the current locale.
238 appears in the same relative position in
240 it represents the characters pairs from the
244 category of the current locale.
246 With the exception of case conversion,
247 characters in the classes are in unspecified order.
249 For specific information as to which
251 characters are included
252 in these classes, see
254 and related manual pages.
256 Represents all characters belonging to the same equivalence class as
258 ordered by their encoded values.
262 repeated occurrences of the character represented by
265 expression is only valid when it occurs in
269 is omitted or is zero, it is be interpreted as large enough to extend
271 sequence to the length of
275 has a leading zero, it is interpreted as an octal value, otherwise,
276 it is interpreted as a decimal value.
280 .Ev LANG , LC_ALL , LC_CTYPE
283 environment variables affect the execution of
290 The following examples are shown as given to the shell:
292 Create a list of the words in file1, one per line, where a word is taken to
293 be a maximal string of letters.
295 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
297 Translate the contents of file1 to upper-case.
299 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
301 (This should be preferred over the traditional
304 .Dq Li "tr a-z A-Z" ,
305 since it works correctly in all locales.)
307 Strip out non-printable characters from file1.
309 .D1 Li "tr -cd \*q[:print:]\*q < file1"
311 Remove diacritical marks from all accented variants of the letter
314 .Dl "tr \*q[=e=]\*q \*qe\*q"
320 did not order characters in range expressions according to the current
321 locale's collation order, making it possible to convert unaccented Latin
322 characters (esp.\& as found in English text) from upper to lower case using
326 .Dq Li "tr A-Z a-z" .
329 now obeys the locale's collation order, this idiom may not produce
330 correct results when there is not a 1:1 mapping between lower and
331 upper case, or when the order of characters within the two cases differs.
334 section above, the character class expressions
338 should be used instead of explicit character ranges like
343 System V has historically implemented character ranges using the syntax
350 standardized by POSIX.
351 System V shell scripts should work under this implementation as long as
352 the range is intended to map in another range, i.e., the command
353 .Dq Li "tr [a-z] [A-Z]"
354 will work as it will map the
362 However, if the shell script is deleting or squeezing characters as in
364 .Dq Li "tr -d [a-z]" ,
370 included in the deletion or compression list which would not have happened
371 under a historic System V implementation.
372 Additionally, any scripts that depended on the sequence
375 represent the three characters
386 utility has historically not permitted the manipulation of NUL bytes in
387 its input and, additionally, stripped NUL's from its input stream.
388 This implementation has removed this behavior as a bug.
392 utility has historically been extremely forgiving of syntax errors,
397 options were ignored unless two strings were specified.
398 This implementation will not permit illegal syntax.
410 character classes are extensions.
412 It should be noted that the feature wherein the last character of
416 has less characters than
418 is permitted by POSIX but is not required.
419 Shell scripts attempting to be portable to other POSIX systems should use
422 convention instead of relying on this behavior.
425 option is an extension to the