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: head/usr.bin/tr/tr.1 233510 2012-03-26 15:18:14Z joel $
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 values in
83 Squeeze multiple occurrences of the characters listed in the last
88 in the input into a single instance of the character.
89 This occurs after all deletion and translation is completed.
91 Guarantee that any output is unbuffered.
94 In the first synopsis form, the characters in
96 are translated into the characters in
98 where the first character in
100 is translated into the first character in
107 the last character found in
113 In the second synopsis form, the characters in
115 are deleted from the input.
117 In the third synopsis form, the characters in
119 are compressed as described for the
123 In the fourth synopsis form, the characters in
125 are deleted from the input, and the characters in
127 are compressed as described for the
131 The following conventions can be used in
135 to specify sets of characters:
136 .Bl -tag -width [:equiv:]
138 Any character not described by one of the following conventions
141 A backslash followed by 1, 2 or 3 octal digits represents a character
142 with that encoded value.
143 To follow an octal sequence with a digit as a character, left zero-pad
144 the octal sequence to the full 3 octal digits.
146 A backslash followed by certain special characters maps to special
149 .It "\ea <alert character>"
150 .It "\eb <backspace>"
151 .It "\ef <form-feed>"
153 .It "\er <carriage return>"
155 .It "\ev <vertical tab>"
158 A backslash followed by any other character maps to that character.
160 For non-octal range endpoints
161 represents the range of characters between the range endpoints, inclusive,
163 as defined by the collation sequence.
164 If either or both of the range endpoints are octal sequences, it
165 represents the range of specific coded values between the
166 range endpoints, inclusive.
171 section below for an important note regarding
172 differences in the way the current
173 implementation interprets range expressions differently from
174 previous implementations.
177 Represents all characters belonging to the defined character class.
179 .Bl -column "phonogram"
180 .It "alnum <alphanumeric characters>"
181 .It "alpha <alphabetic characters>"
182 .It "blank <whitespace characters>"
183 .It "cntrl <control characters>"
184 .It "digit <numeric characters>"
185 .It "graph <graphic characters>"
186 .It "ideogram <ideographic characters>"
187 .It "lower <lower-case alphabetic characters>"
188 .It "phonogram <phonographic characters>"
189 .It "print <printable characters>"
190 .It "punct <punctuation characters>"
191 .It "rune <valid characters>"
192 .It "space <space characters>"
193 .It "special <special characters>"
194 .It "upper <upper-case characters>"
195 .It "xdigit <hexadecimal characters>"
198 .\" All classes may be used in
206 .\" options are specified.
207 .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
209 .\" and then only when the corresponding class (``upper'' for ``lower''
210 .\" and vice-versa) is specified in the same relative position in
219 appears in the same relative position in
221 it represents the characters pairs from the
225 category of the current locale.
232 appears in the same relative position in
234 it represents the characters pairs from the
238 category of the current locale.
240 With the exception of case conversion,
241 characters in the classes are in unspecified order.
243 For specific information as to which
245 characters are included
246 in these classes, see
248 and related manual pages.
250 Represents all characters belonging to the same equivalence class as
252 ordered by their encoded values.
256 repeated occurrences of the character represented by
259 expression is only valid when it occurs in
263 is omitted or is zero, it is be interpreted as large enough to extend
265 sequence to the length of
269 has a leading zero, it is interpreted as an octal value, otherwise,
270 it is interpreted as a decimal value.
274 .Ev LANG , LC_ALL , LC_CTYPE
277 environment variables affect the execution of
284 The following examples are shown as given to the shell:
286 Create a list of the words in file1, one per line, where a word is taken to
287 be a maximal string of letters.
289 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
291 Translate the contents of file1 to upper-case.
293 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
295 (This should be preferred over the traditional
298 .Dq Li "tr a-z A-Z" ,
299 since it works correctly in all locales.)
301 Strip out non-printable characters from file1.
303 .D1 Li "tr -cd \*q[:print:]\*q < file1"
305 Remove diacritical marks from all accented variants of the letter
308 .Dl "tr \*q[=e=]\*q \*qe\*q"
314 did not order characters in range expressions according to the current
315 locale's collation order, making it possible to convert unaccented Latin
316 characters (esp.\& as found in English text) from upper to lower case using
320 .Dq Li "tr A-Z a-z" .
323 now obeys the locale's collation order, this idiom may not produce
324 correct results when there is not a 1:1 mapping between lower and
325 upper case, or when the order of characters within the two cases differs.
328 section above, the character class expressions
332 should be used instead of explicit character ranges like
337 System V has historically implemented character ranges using the syntax
344 standardized by POSIX.
345 System V shell scripts should work under this implementation as long as
346 the range is intended to map in another range, i.e., the command
347 .Dq Li "tr [a-z] [A-Z]"
348 will work as it will map the
356 However, if the shell script is deleting or squeezing characters as in
358 .Dq Li "tr -d [a-z]" ,
364 included in the deletion or compression list which would not have happened
365 under a historic System V implementation.
366 Additionally, any scripts that depended on the sequence
369 represent the three characters
380 utility has historically not permitted the manipulation of NUL bytes in
381 its input and, additionally, stripped NUL's from its input stream.
382 This implementation has removed this behavior as a bug.
386 utility has historically been extremely forgiving of syntax errors,
391 options were ignored unless two strings were specified.
392 This implementation will not permit illegal syntax.
404 character classes are extensions.
406 It should be noted that the feature wherein the last character of
410 has less characters than
412 is permitted by POSIX but is not required.
413 Shell scripts attempting to be portable to other POSIX systems should use
416 convention instead of relying on this behavior.
419 option is an extension to the