Remove advertising header from man pages.
[dragonfly.git] / usr.bin / tr / tr.1
1 .\" Copyright (c) 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the Institute of Electrical and Electronics Engineers, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
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 .\" 4. 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.
18 .\"
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
29 .\" SUCH DAMAGE.
30 .\"
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 $
33 .\"
34 .Dd November 25, 2010
35 .Dt TR 1
36 .Os
37 .Sh NAME
38 .Nm tr
39 .Nd translate characters
40 .Sh SYNOPSIS
41 .Nm
42 .Op Fl Ccsu
43 .Ar string1 string2
44 .Nm
45 .Op Fl Ccu
46 .Fl d
47 .Ar string1
48 .Nm
49 .Op Fl Ccu
50 .Fl s
51 .Ar string1
52 .Nm
53 .Op Fl Ccu
54 .Fl ds
55 .Ar string1 string2
56 .Sh DESCRIPTION
57 The
58 .Nm
59 utility copies the standard input to the standard output with substitution
60 or deletion of selected characters.
61 .Pp
62 The following options are available:
63 .Bl -tag -width Ds
64 .It Fl C
65 Complement the set of characters in
66 .Ar string1 ,
67 that is
68 .Dq "-C ab"
69 includes every character except for
70 .Dq a
71 and
72 .Dq b .
73 .It Fl c
74 Same as
75 .Fl C
76 but complement the set of byte values in
77 .Ar string1 .
78 .It Fl d
79 The
80 .Fl d
81 option causes characters to be deleted from the input.
82 .It Fl s
83 The
84 .Fl s
85 option squeezes multiple occurrences of the characters listed in the last
86 operand (either
87 .Ar string1
88 or
89 .Ar string2 )
90 in the input into a single instance of the character.
91 This occurs after all deletion and translation is completed.
92 .It Fl u
93 The
94 .Fl u
95 option guarantees that any output is unbuffered.
96 .El
97 .Pp
98 In the first synopsis form, the characters in
99 .Ar string1
100 are translated into the characters in
101 .Ar string2
102 where the first character in
103 .Ar string1
104 is translated into the first character in
105 .Ar string2
106 and so on.
107 If
108 .Ar string1
109 is longer than
110 .Ar string2 ,
111 the last character found in
112 .Ar string2
113 is duplicated until
114 .Ar string1
115 is exhausted.
116 .Pp
117 In the second synopsis form, the characters in
118 .Ar string1
119 are deleted from the input.
120 .Pp
121 In the third synopsis form, the characters in
122 .Ar string1
123 are compressed as described for the
124 .Fl s
125 option.
126 .Pp
127 In the fourth synopsis form, the characters in
128 .Ar string1
129 are deleted from the input, and the characters in
130 .Ar string2
131 are compressed as described for the
132 .Fl s
133 option.
134 .Pp
135 The following conventions can be used in
136 .Ar string1
137 and
138 .Ar string2
139 to specify sets of characters:
140 .Bl -tag -width [:equiv:]
141 .It character
142 Any character not described by one of the following conventions
143 represents itself.
144 .It \eoctal
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.
149 .It \echaracter
150 A backslash followed by certain special characters maps to special
151 values.
152 .Bl -column "\ea"
153 .It "\ea        <alert character>"
154 .It "\eb        <backspace>"
155 .It "\ef        <form-feed>"
156 .It "\en        <newline>"
157 .It "\er        <carriage return>"
158 .It "\et        <tab>"
159 .It "\ev        <vertical tab>"
160 .El
161 .Pp
162 A backslash followed by any other character maps to that character.
163 .It c-c
164 Represents the range of characters between the range endpoints, inclusively.
165 .It [:class:]
166 Represents all characters belonging to the defined character class.
167 Class names are:
168 .Bl -column "xdigit"
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>"
180 .El
181 .Pp
182 .\" All classes may be used in
183 .\" .Ar string1 ,
184 .\" and in
185 .\" .Ar string2
186 .\" when both the
187 .\" .Fl d
188 .\" and
189 .\" .Fl s
190 .\" options are specified.
191 .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
192 .\" .Ar string2
193 .\" and then only when the corresponding class (``upper'' for ``lower''
194 .\" and vice-versa) is specified in the same relative position in
195 .\" .Ar string1 .
196 .\" .Pp
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
200 ascending order.
201 .Pp
202 For specific information as to which ASCII characters are included
203 in these classes, see
204 .Xr ctype 3
205 and related manual pages.
206 .It [=equiv=]
207 Represents all characters belonging to the same equivalence class as
208 .Ar equiv ,
209 ordered by their encoded values.
210 .It [#*n]
211 Represents
212 .Ar n
213 repeated occurrences of the character represented by
214 .Ar # .
215 This
216 expression is only valid when it occurs in
217 .Ar string2 .
218 If
219 .Ar n
220 is omitted or is zero, it is be interpreted as large enough to extend
221 .Ar string2
222 sequence to the length of
223 .Ar string1 .
224 If
225 .Ar n
226 has a leading zero, it is interpreted as an octal value, otherwise,
227 it's interpreted as a decimal value.
228 .El
229 .Sh ENVIRONMENT
230 The
231 .Ev LANG ,
232 .Ev LC_ALL ,
233 .Ev LC_CTYPE
234 and
235 .Ev LC_COLLATE
236 environment variables affect the execution of
237 .Nm
238 as described in
239 .Xr environ 7 .
240 .Sh EXIT STATUS
241 .Ex -std
242 .Sh EXAMPLES
243 The following examples are shown as given to the shell:
244 .Pp
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.
247 .Pp
248 .D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
249 .Pp
250 Translate the contents of file1 to upper-case.
251 .Pp
252 .D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
253 .Pp
254 Strip out non-printable characters from file1.
255 .Pp
256 .D1 Li "tr -cd \*q[:print:]\*q < file1"
257 .Pp
258 Remove diacritical marks from all accented variants of the letter
259 .Sq e :
260 .Pp
261 .Dl "tr \*q[=e=]\*q \*qe\*q"
262 .Sh COMPATIBILITY
263 System V has historically implemented character ranges using the syntax
264 ``[c-c]'' instead of the ``c-c'' used by historic
265 .Bx
266 implementations and
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
271 .Ar string1
272 to the ``['' character in
273 .Ar string2 .
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''.
281 .Pp
282 The
283 .Nm
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.
287 .Pp
288 The
289 .Nm
290 utility has historically been extremely forgiving of syntax errors,
291 for example, the
292 .Fl c
293 and
294 .Fl s
295 options were ignored unless two strings were specified.
296 This implementation will not permit illegal syntax.
297 .Sh STANDARDS
298 The
299 .Nm
300 utility conforms to
301 .St -p1003.1-2001 .
302 .Pp
303 It should be noted that the feature wherein the last character of
304 .Ar string2
305 is duplicated if
306 .Ar string2
307 has less characters than
308 .Ar string1
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.
312 The
313 .Fl u
314 option is an extension to the
315 .St -p1003.1-2001
316 standard.