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
36 .\" $FreeBSD: src/usr.bin/tr/tr.1,v 1.5.2.7 2002/07/29 12:59:33 tjr Exp $
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 Complements the set of characters in
71 that is ``-c ab'' includes every character except for ``a'' and ``b''.
75 option causes characters to be deleted from the input.
79 option squeezes multiple occurrences of the characters listed in the last
84 in the input into a single instance of the character.
85 This occurs after all deletion and translation is completed.
89 option guarantees that any output is unbuffered.
92 In the first synopsis form, the characters in
94 are translated into the characters in
96 where the first character in
98 is translated into the first character in
105 the last character found in
111 In the second synopsis form, the characters in
113 are deleted from the input.
115 In the third synopsis form, the characters in
117 are compressed as described for the
121 In the fourth synopsis form, the characters in
123 are deleted from the input, and the characters in
125 are compressed as described for the
129 The following conventions can be used in
133 to specify sets of characters:
134 .Bl -tag -width [:equiv:]
136 Any character not described by one of the following conventions
139 A backslash followed by 1, 2 or 3 octal digits represents a character
140 with that encoded value.
141 To follow an octal sequence with a digit as a character, left zero-pad
142 the octal sequence to the full 3 octal digits.
144 A backslash followed by certain special characters maps to special
148 .It "\ea <alert character>
152 .It "\er <carriage return>
154 .It "\ev <vertical tab>
157 A backslash followed by any other character maps to that character.
159 Represents the range of characters between the range endpoints, inclusively.
161 Represents all characters belonging to the defined character class.
165 .It "alnum <alphanumeric characters>
166 .It "alpha <alphabetic characters>
167 .It "cntrl <control characters>
168 .It "digit <numeric characters>
169 .It "graph <graphic characters>
170 .It "lower <lower-case alphabetic characters>
171 .It "print <printable characters>
172 .It "punct <punctuation characters>
173 .It "space <space characters>
174 .It "upper <upper-case characters>
175 .It "xdigit <hexadecimal characters>
178 .\" All classes may be used in
186 .\" options are specified.
187 .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
189 .\" and then only when the corresponding class (``upper'' for ``lower''
190 .\" and vice-versa) is specified in the same relative position in
193 With the exception of the ``upper'' and ``lower'' classes, characters
194 in the classes are in unspecified order.
195 In the ``upper'' and ``lower'' classes, characters are entered in
198 For specific information as to which ASCII characters are included
199 in these classes, see
201 and related manual pages.
203 Represents all characters belonging to the same equivalence class as
205 ordered by their encoded values.
209 repeated occurrences of the character represented by
212 expression is only valid when it occurs in
216 is omitted or is zero, it is be interpreted as large enough to extend
218 sequence to the length of
222 has a leading zero, it is interpreted as an octal value, otherwise,
223 it's interpreted as a decimal value.
232 environment variables affect the execution of
239 The following examples are shown as given to the shell:
241 Create a list of the words in file1, one per line, where a word is taken to
242 be a maximal string of letters.
244 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
246 Translate the contents of file1 to upper-case.
248 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
250 Strip out non-printable characters from file1.
252 .D1 Li "tr -cd \*q[:print:]\*q < file1"
254 Remove diacritical marks from all accented variants of the letter
257 .Dl "tr \*q[=e=]\*q \*qe\*q"
259 System V has historically implemented character ranges using the syntax
260 ``[c-c]'' instead of the ``c-c'' used by historic
263 standardized by POSIX.
264 System V shell scripts should work under this implementation as long as
265 the range is intended to map in another range, i.e. the command
266 ``tr [a-z] [A-Z]'' will work as it will map the ``['' character in
268 to the ``['' character in
270 However, if the shell script is deleting or squeezing characters as in
271 the command ``tr -d [a-z]'', the characters ``['' and ``]'' will be
272 included in the deletion or compression list which would not have happened
273 under an historic System V implementation.
274 Additionally, any scripts that depended on the sequence ``a-z'' to
275 represent the three characters ``a'', ``-'' and ``z'' will have to be
276 rewritten as ``a\e-z''.
280 utility has historically not permitted the manipulation of NUL bytes in
281 its input and, additionally, stripped NUL's from its input stream.
282 This implementation has removed this behavior as a bug.
286 utility has historically been extremely forgiving of syntax errors,
291 options were ignored unless two strings were specified.
292 This implementation will not permit illegal syntax.
296 utility is expected to be
299 It should be noted that the feature wherein the last character of
303 has less characters than
305 is permitted by POSIX but is not required.
306 Shell scripts attempting to be portable to other POSIX systems should use
307 the ``[#*]'' convention instead of relying on this behavior.
310 option is an extension to the