6001 strcat(9f) needs a manpage
[unleashed.git] / usr / src / man / man1 / tr.1
blobe9b58da3e806fe1fbde380bbdc8d0c753e68173b
1 '\" te
2 .\" Copyright 1989 AT&T Copyright (c) 1992, X/Open Company Limited All Rights Reserved
3 .\" Portions Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved
4 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at  http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text
6 .\" are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical
7 .\" and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\"  This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
10 .\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with
11 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH TR 1 "Mar 3, 2009"
13 .SH NAME
14 tr \- translate characters
15 .SH SYNOPSIS
16 .LP
17 .nf
18 \fB/usr/bin/tr\fR [\fB-cds\fR] [\fIstring1\fR [\fIstring2\fR]]
19 .fi
21 .LP
22 .nf
23 \fB/usr/xpg4/bin/tr\fR [\fB-cs\fR] \fIstring1\fR \fIstring2\fR
24 .fi
26 .LP
27 .nf
28 \fB/usr/xpg4/bin/tr\fR \fB-s\fR | \fB-d\fR [\fB-c\fR] \fIstring1\fR
29 .fi
31 .LP
32 .nf
33 \fB/usr/xpg4/bin/tr\fR \fB-ds\fR [\fB-c\fR] \fIstring1\fR \fIstring2\fR
34 .fi
36 .LP
37 .nf
38 \fB/usr/xpg6/bin/tr\fR [\fB-c\fR | \fB-C\fR] [\fB-s\fR] \fIstring1\fR \fIstring2\fR
39 .fi
41 .LP
42 .nf
43 \fB/usr/xpg6/bin/tr\fR \fB-s\fR [\fB-c\fR | \fB-C\fR] \fIstring1\fR
44 .fi
46 .LP
47 .nf
48 \fB/usr/xpg6/bin/tr\fR \fB-d\fR [\fB-c\fR | \fB-C\fR] \fIstring1\fR
49 .fi
51 .LP
52 .nf
53 \fB/usr/xpg6/bin/tr\fR \fB-ds\fR [\fB-c\fR | \fB-C\fR] \fIstring1\fR \fIstring2\fR
54 .fi
56 .SH DESCRIPTION
57 .sp
58 .LP
59 The \fBtr\fR utility copies the standard input to the standard output with
60 substitution or deletion of selected characters. The options specified and the
61 \fIstring1\fR and \fIstring2\fR operands control translations that occur while
62 copying characters and single-character collating elements.
63 .SH OPTIONS
64 .sp
65 .LP
66 The following options are supported:
67 .sp
68 .ne 2
69 .na
70 \fB\fB-c\fR\fR
71 .ad
72 .RS 6n
73 Complements the set of values specified by \fIstring1\fR.
74 .RE
76 .sp
77 .ne 2
78 .na
79 \fB\fB-C\fR\fR
80 .ad
81 .RS 6n
82 Complements the set of characters specified by \fIstring1\fR.
83 .RE
85 .sp
86 .ne 2
87 .na
88 \fB\fB-d\fR\fR
89 .ad
90 .RS 6n
91 Deletes all occurrences of input characters that are specified by
92 \fIstring1\fR.
93 .RE
95 .sp
96 .ne 2
97 .na
98 \fB\fB-s\fR\fR
99 .ad
100 .RS 6n
101 Replaces instances of repeated characters with a single character.
106 When the \fB-d\fR option is not specified:
107 .RS +4
109 .ie t \(bu
110 .el o
111 Each input character found in the array specified by \fIstring1\fR is replaced
112 by the character in the same relative position in the array specified by
113 \fIstring2\fR. When the array specified by \fIstring2\fR is shorter than the
114 one specified by \fIstring1\fR, the results are unspecified.
116 .RS +4
118 .ie t \(bu
119 .el o
120 If the \fB-c\fR option is specified, the complements of the values specified by
121 \fIstring1\fR are placed in the array in ascending order by binary value.
123 .RS +4
125 .ie t \(bu
126 .el o
127 If the \fB-C\fR option is specified, the complements of the characters
128 specified by \fIstring1\fR (the set of all characters in the current character
129 set, as defined by the current setting of \fBLC_CTYPE\fR, except for those
130 actually specified in the \fIstring1\fR operand) are placed in the array in
131 ascending collation sequence, as defined by the current setting of
132 \fBLC_COLLATE\fR.
134 .RS +4
136 .ie t \(bu
137 .el o
138 Because the order in which characters specified by character class expressions
139 or equivalence class expressions is undefined, such expressions should only be
140 used if the intent is to map several characters into one. An exception is case
141 conversion, as described previously.
145 When the \fB-d\fR option is specified:
146 .RS +4
148 .ie t \(bu
149 .el o
150 Input characters found in the array specified by \fIstring1\fR are deleted.
152 .RS +4
154 .ie t \(bu
155 .el o
156 When the \fB-C\fR option is specified with \fB-d\fR, all values except those
157 specified by \fIstring1\fR are deleted. The contents of \fIstring2\fR are
158 ignored, unless the \fB-s\fR option is also specified.
160 .RS +4
162 .ie t \(bu
163 .el o
164 If the \fB-c\fR option is specified, the complements of the values specified by
165 \fIstring1\fR are placed in the array in ascending order by binary value.
167 .RS +4
169 .ie t \(bu
170 .el o
171 The same string cannot be used for both the \fB-d\fR and the \fB-s\fR option.
172 When both options are specified, both \fIstring1\fR (used for deletion) and
173 \fIstring2\fR (used for squeezing) are required.
177 When the \fB-s\fR option is specified, after any deletions or translations have
178 taken place, repeated sequences of the same character is replaced by one
179 occurrence of the same character, if the character is found in the array
180 specified by the last operand. If the last operand contains a character class,
181 such as the following example:
183 .in +2
185 \fBtr -s '[:space:]'\fR
187 .in -2
192 the last operand's array contains all of the characters in that character
193 class. However, in a case conversion, as described previously, such as
195 .in +2
197 \fBtr -s '[:upper:]' '[:lower:]'\fR
199 .in -2
204 the last operand's array contains only those characters defined as the second
205 characters in each of the \fBtoupper\fR or \fBtolower\fR character pairs, as
206 appropriate. (See \fBtoupper\fR(3C) and \fBtolower\fR(3C)).
209 An empty string used for \fIstring1\fR or \fIstring2\fR produces undefined
210 results.
211 .SH OPERANDS
214 The following operands are supported:
216 .ne 2
218 \fB\fIstring1\fR\fR
222 \fB\fIstring2\fR\fR
224 .RS 11n
225 Translation control strings. Each string represents a set of characters to be
226 converted into an array of characters used for the translation.
231 The operands \fIstring1\fR and \fIstring2\fR (if specified) define two arrays
232 of characters. The constructs in the following list can be used to specify
233 characters or single-character collating elements. If any of the constructs
234 result in multi-character collating elements, \fBtr\fR excludes, without a
235 diagnostic, those multi-character elements from the resulting array.
237 .ne 2
239 \fB\fIcharacter\fR\fR
241 .RS 15n
242 Any character not described by one of the conventions below represents itself.
246 .ne 2
248 \fB\fB\e\fR\fIoctal\fR\fR
250 .RS 15n
251 Octal sequences can be used to represent characters with specific coded values.
252 An octal sequence consists of a backslash followed by the longest sequence of
253 one-, two-, or three-octal-digit characters (01234567). The sequence causes the
254 character whose encoding is represented by the one-, two- or three-digit octal
255 integer to be placed into the array. Multi-byte characters require multiple,
256 concatenated escape sequences of this type, including the leading \e for each
257 byte.
261 .ne 2
263 \fB\fB\e\fR\fIcharacter\fR\fR
265 .RS 15n
266 The backslash-escape sequences \fB\ea\fR, \fB\eb\fR, \fB\ef\fR, \fB\en\fR,
267 \fB\er\fR, \fB\et\fR, and \fB\ev\fR are supported. The results of using any
268 other character, other than an octal digit, following the backslash are
269 unspecified.
272 .SS "/usr/xpg4/bin/tr"
274 .ne 2
276 \fB\fIc-c\fR\fR
278 .RS 7n
282 .SS "/usr/bin/tr"
284 .ne 2
286 \fB[\fIc-c\fR]\fR
288 .RS 13n
289 In the POSIX locale, this construct represents the range of collating elements
290 between the range endpoints (as long as neither endpoint is an octal sequence
291 of the form \fB\e\fR\fIoctal\fR), inclusively, as defined by the collation
292 sequence. The characters or collating elements in the range are placed in the
293 array in ascending collation sequence. If the second endpoint precedes the
294 starting endpoint in the collation sequence, it is unspecified whether the
295 range of collating elements is empty, or this construct is treated as invalid.
296 In locales other than the POSIX locale, this construct has unspecified
297 behavior.
299 If either or both of the range endpoints are octal sequences of the form
300 \fB\e\fR\fIoctal\fR, represents the range of specific coded binary values
301 between two range endpoints, inclusively.
305 .ne 2
307 \fB\fB[:\fR\fIclass\fR\fB:]\fR\fR
309 .RS 13n
310 Represents all characters belonging to the defined character class, as defined
311 by the current setting of the \fBLC_CTYPE\fR locale category. The following
312 character class names are accepted when specified in \fIstring1\fR:
314 .in +2
316 alnum  blank  digit  lower  punct  upper
317 alpha  cntrl  graph  print  space  xdigit
319 .in -2
322 In addition, character class expressions of the form \fB[:\fR\fIname\fR\fB:]\fR
323 are recognized in those locales where the \fIname\fR keyword has been given a
324 \fBcharclass\fR definition in the \fBLC_CTYPE\fR category.
326 When both the \fB-d\fR and \fB-s\fR options are specified, any of the character
327 class names are accepted in \fIstring2\fR. Otherwise, only character class
328 names \fBlower\fR or \fBupper\fR are valid in \fIstring2\fR and then only if
329 the corresponding character class \fBupper\fR and \fBlower\fR, respectively, is
330 specified in the same relative position in \fIstring1\fR. Such a specification
331 is interpreted as a request for case conversion. When \fB[:lower:]\fR appears
332 in \fIstring1\fR and \fB[:upper:]\fR appears in \fIstring2,\fR the arrays
333 contain the characters from the \fBtoupper\fR mapping in the \fBLC_CTYPE\fR
334 category of the current locale. When \fB[:upper:]\fR appears in \fIstring1\fR
335 and \fB[:lower:]\fR appears in \fIstring2,\fR the arrays contain the characters
336 from the \fBtolower\fR mapping in the \fBLC_CTYPE\fR category of the current
337 locale. The first character from each mapping pair is in the array for
338 \fIstring1\fR and the second character from each mapping pair is in the array
339 for \fIstring2\fR in the same relative position.
341 Except for case conversion, the characters specified by a character class
342 expression are placed in the array in an unspecified order.
344 If the name specified for \fIclass\fR does not define a valid character class
345 in the current locale, the behavior is undefined.
349 .ne 2
351 \fB\fB[=\fR\fIequiv\fR\fB=]\fR\fR
353 .RS 13n
354 Represents all characters or collating elements belonging to the same
355 equivalence class as \fIequiv\fR, as defined by the current setting of the
356 \fBLC_COLLATE\fR locale category. An equivalence class expression is allowed
357 only in \fIstring1\fR, or in \fIstring2\fR when it is being used by the
358 combined \fB-d\fR and \fB-s\fR options. The characters belonging to the
359 equivalence class are placed in the array in an unspecified order.
363 .ne 2
365 \fB[\fIx*n\fR]\fR
367 .RS 13n
368 Represents \fIn\fR repeated occurrences of the character \fIx\fR. Because this
369 expression is used to map multiple characters to one, it is only valid when it
370 occurs in \fIstring2\fR. If \fIn\fR has a leading \fB0\fR, it is interpreted
371 as an octal value. Otherwise, it is interpreted as a decimal value.
373 If \fIn\fR is omitted or is \fB0\fR, \fB/usr/bin/tr\fR interprets this as huge;
374 \fB/usr/xpg4/bin/tr\fR and \fB/usr/xpg6/bin/tr\fR interprets this as large
375 enough to extend the\fIstring2\fR-based sequence to the length of the
376 \fIstring1\fR-based sequence.
379 .SH USAGE
382 See \fBlargefile\fR(5) for the description of the behavior of \fBtr\fR when
383 encountering files greater than or equal to 2 Gbyte ( 2^31 bytes).
384 .SH EXAMPLES
386 \fBExample 1 \fRCreating a list of words
389 The following example creates a list of all words in \fIfile1\fR, one per line
390 in \fIfile2\fR, where a word is taken to be a maximal string of letters.
393 .in +2
395 \fBtr \(mics "[:alpha:]" "[\en*]" <file1 >file2\fR
397 .in -2
401 \fBExample 2 \fRTranslating characters
404 This example translates all lower-case characters in \fBfile1\fR to upper-case
405 and writes the results to standard output.
408 .in +2
410 \fBtr "[:lower:]" "[:upper:]" <file1\fR
412 .in -2
417 Notice that the caveat expressed in the corresponding example in XPG3 is no
418 longer in effect. This case conversion is now a special case that employs the
419 \fBtolower\fR and \fBtoupper\fR classifications, ensuring that proper mapping
420 is accomplished (when the locale is correctly defined).
423 \fBExample 3 \fRIdentifying equivalent characters
426 This example uses an equivalence class to identify accented variants of the
427 base character \fBe\fR in \fBfile1\fR, which are stripped of diacritical marks
428 and written to \fBfile2\fR.
431 .in +2
433 \fBtr "[=e=]" e <file1 >file2\fR
435 .in -2
438 .SH ENVIRONMENT VARIABLES
441 See \fBenviron\fR(5) for descriptions of the following environment variables
442 that affect the execution of \fBtr\fR: \fBLANG\fR, \fBLC_ALL\fR,
443 \fBLC_COLLATE\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR.
444 .SH EXIT STATUS
447 The following exit values are returned:
449 .ne 2
451 \fB\fB0\fR\fR
453 .RS 6n
454 All input was processed successfully.
458 .ne 2
460 \fB\fB>0\fR\fR
462 .RS 6n
463 An error occurred.
466 .SH ATTRIBUTES
469 See \fBattributes\fR(5) for descriptions of the following attributes:
470 .SS "/usr/bin/tr"
475 box;
476 c | c
477 l | l .
478 ATTRIBUTE TYPE  ATTRIBUTE VALUE
480 CSI     Enabled
483 .SS "/usr/xpg4/bin/tr"
488 box;
489 c | c
490 l | l .
491 ATTRIBUTE TYPE  ATTRIBUTE VALUE
493 CSI     Enabled
495 Interface Stability     Committed
497 Standard        See \fBstandards\fR(5).
500 .SS "/usr/xpg6/bin/tr"
505 box;
506 c | c
507 l | l .
508 ATTRIBUTE TYPE  ATTRIBUTE VALUE
510 CSI     Enabled
512 Interface Stability     Committed
514 Standard        See \fBstandards\fR(5).
517 .SH SEE ALSO
520 \fBed\fR(1), \fBsed\fR(1), \fBsh\fR(1), \fBtolower\fR(3C), \fBtoupper\fR(3C),
521 \fBascii\fR(5), \fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5),
522 \fBregex\fR(5), \fBstandards\fR(5)
523 .SH NOTES
526 Unlike some previous versions, \fB/usr/xpg4/bin/tr\fR correctly processes
527 \fBNUL\fR characters in its input stream. \fBNUL\fR characters can be stripped
528 by using \fBtr\fR \fB-d\fR \fB\&'\e000'\fR.