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. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)tr.1 8.1 (Berkeley) 6/6/93
32 .\" $FreeBSD: src/usr.bin/tr/tr.1,v 1.5.2.7 2002/07/29 12:59:33 tjr Exp $
39 .Nd translate characters
59 utility copies the standard input to the standard output with substitution
60 or deletion of selected characters.
62 The following options are available:
65 Complement the set of characters in
69 includes every character except for
76 but complement the set of byte values in
81 option causes characters to be deleted from the input.
85 option squeezes multiple occurrences of the characters listed in the last
90 in the input into a single instance of the character.
91 This occurs after all deletion and translation is completed.
95 option guarantees 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
153 .It "\ea <alert character>"
154 .It "\eb <backspace>"
155 .It "\ef <form-feed>"
157 .It "\er <carriage return>"
159 .It "\ev <vertical tab>"
162 A backslash followed by any other character maps to that character.
164 Represents the range of characters between the range endpoints, inclusively.
166 Represents all characters belonging to the defined character class.
169 .It "alnum <alphanumeric characters>"
170 .It "alpha <alphabetic characters>"
171 .It "cntrl <control characters>"
172 .It "digit <numeric characters>"
173 .It "graph <graphic characters>"
174 .It "lower <lower-case alphabetic characters>"
175 .It "print <printable characters>"
176 .It "punct <punctuation characters>"
177 .It "space <space characters>"
178 .It "upper <upper-case characters>"
179 .It "xdigit <hexadecimal characters>"
182 .\" All classes may be used in
190 .\" options are specified.
191 .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
193 .\" and then only when the corresponding class (``upper'' for ``lower''
194 .\" and vice-versa) is specified in the same relative position in
197 With the exception of the ``upper'' and ``lower'' classes, characters
198 in the classes are in unspecified order.
199 In the ``upper'' and ``lower'' classes, characters are entered in
202 For specific information as to which ASCII characters are included
203 in these classes, see
205 and related manual pages.
207 Represents all characters belonging to the same equivalence class as
209 ordered by their encoded values.
213 repeated occurrences of the character represented by
216 expression is only valid when it occurs in
220 is omitted or is zero, it is be interpreted as large enough to extend
222 sequence to the length of
226 has a leading zero, it is interpreted as an octal value, otherwise,
227 it's interpreted as a decimal value.
236 environment variables affect the execution of
243 The following examples are shown as given to the shell:
245 Create a list of the words in file1, one per line, where a word is taken to
246 be a maximal string of letters.
248 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
250 Translate the contents of file1 to upper-case.
252 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
254 Strip out non-printable characters from file1.
256 .D1 Li "tr -cd \*q[:print:]\*q < file1"
258 Remove diacritical marks from all accented variants of the letter
261 .Dl "tr \*q[=e=]\*q \*qe\*q"
263 System V has historically implemented character ranges using the syntax
264 ``[c-c]'' instead of the ``c-c'' used by historic
267 standardized by POSIX.
268 System V shell scripts should work under this implementation as long as
269 the range is intended to map in another range, i.e. the command
270 ``tr [a-z] [A-Z]'' will work as it will map the ``['' character in
272 to the ``['' character in
274 However, if the shell script is deleting or squeezing characters as in
275 the command ``tr -d [a-z]'', the characters ``['' and ``]'' will be
276 included in the deletion or compression list which would not have happened
277 under an historic System V implementation.
278 Additionally, any scripts that depended on the sequence ``a-z'' to
279 represent the three characters ``a'', ``-'' and ``z'' will have to be
280 rewritten as ``a\e-z''.
284 utility has historically not permitted the manipulation of NUL bytes in
285 its input and, additionally, stripped NUL's from its input stream.
286 This implementation has removed this behavior as a bug.
290 utility has historically been extremely forgiving of syntax errors,
295 options were ignored unless two strings were specified.
296 This implementation will not permit illegal syntax.
303 It should be noted that the feature wherein the last character of
307 has less characters than
309 is permitted by POSIX but is not required.
310 Shell scripts attempting to be portable to other POSIX systems should use
311 the ``[#*]'' convention instead of relying on this behavior.
314 option is an extension to the