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.\" 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. 22.\" 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 33.\" SUCH DAMAGE. 34.\" 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 $ 37.\" 38.Dd November 25, 2010 39.Dt TR 1 40.Os 41.Sh NAME 42.Nm tr 43.Nd translate characters 44.Sh SYNOPSIS 45.Nm 46.Op Fl Ccsu 47.Ar string1 string2 48.Nm 49.Op Fl Ccu 50.Fl d 51.Ar string1 52.Nm 53.Op Fl Ccu 54.Fl s 55.Ar string1 56.Nm 57.Op Fl Ccu 58.Fl ds 59.Ar string1 string2 60.Sh DESCRIPTION 61The 62.Nm 63utility copies the standard input to the standard output with substitution 64or deletion of selected characters. 65.Pp 66The following options are available: 67.Bl -tag -width Ds 68.It Fl C 69Complement the set of characters in 70.Ar string1 , 71that is 72.Dq "-C ab" 73includes every character except for 74.Dq a 75and 76.Dq b . 77.It Fl c 78Same as 79.Fl C 80but complement the set of byte values in 81.Ar string1 . 82.It Fl d 83The 84.Fl d 85option causes characters to be deleted from the input. 86.It Fl s 87The 88.Fl s 89option squeezes multiple occurrences of the characters listed in the last 90operand (either 91.Ar string1 92or 93.Ar string2 ) 94in the input into a single instance of the character. 95This occurs after all deletion and translation is completed. 96.It Fl u 97The 98.Fl u 99option guarantees that any output is unbuffered. 100.El 101.Pp 102In the first synopsis form, the characters in 103.Ar string1 104are translated into the characters in 105.Ar string2 106where the first character in 107.Ar string1 108is translated into the first character in 109.Ar string2 110and so on. 111If 112.Ar string1 113is longer than 114.Ar string2 , 115the last character found in 116.Ar string2 117is duplicated until 118.Ar string1 119is exhausted. 120.Pp 121In the second synopsis form, the characters in 122.Ar string1 123are deleted from the input. 124.Pp 125In the third synopsis form, the characters in 126.Ar string1 127are compressed as described for the 128.Fl s 129option. 130.Pp 131In the fourth synopsis form, the characters in 132.Ar string1 133are deleted from the input, and the characters in 134.Ar string2 135are compressed as described for the 136.Fl s 137option. 138.Pp 139The following conventions can be used in 140.Ar string1 141and 142.Ar string2 143to specify sets of characters: 144.Bl -tag -width [:equiv:] 145.It character 146Any character not described by one of the following conventions 147represents itself. 148.It \eoctal 149A backslash followed by 1, 2 or 3 octal digits represents a character 150with that encoded value. 151To follow an octal sequence with a digit as a character, left zero-pad 152the octal sequence to the full 3 octal digits. 153.It \echaracter 154A backslash followed by certain special characters maps to special 155values. 156.Bl -column "\ea" 157.It "\ea <alert character>" 158.It "\eb <backspace>" 159.It "\ef <form-feed>" 160.It "\en <newline>" 161.It "\er <carriage return>" 162.It "\et <tab>" 163.It "\ev <vertical tab>" 164.El 165.Pp 166A backslash followed by any other character maps to that character. 167.It c-c 168Represents the range of characters between the range endpoints, inclusively. 169.It [:class:] 170Represents all characters belonging to the defined character class. 171Class names are: 172.Bl -column "xdigit" 173.It "alnum <alphanumeric characters> 174.It "alpha <alphabetic characters> 175.It "cntrl <control characters> 176.It "digit <numeric characters> 177.It "graph <graphic characters> 178.It "lower <lower-case alphabetic characters> 179.It "print <printable characters> 180.It "punct <punctuation characters> 181.It "space <space characters> 182.It "upper <upper-case characters> 183.It "xdigit <hexadecimal characters> 184.El 185.Pp 186.\" All classes may be used in 187.\" .Ar string1 , 188.\" and in 189.\" .Ar string2 190.\" when both the 191.\" .Fl d 192.\" and 193.\" .Fl s 194.\" options are specified. 195.\" Otherwise, only the classes ``upper'' and ``lower'' may be used in 196.\" .Ar string2 197.\" and then only when the corresponding class (``upper'' for ``lower'' 198.\" and vice-versa) is specified in the same relative position in 199.\" .Ar string1 . 200.\" .Pp 201With the exception of the ``upper'' and ``lower'' classes, characters 202in the classes are in unspecified order. 203In the ``upper'' and ``lower'' classes, characters are entered in 204ascending order. 205.Pp 206For specific information as to which ASCII characters are included 207in these classes, see 208.Xr ctype 3 209and related manual pages. 210.It [=equiv=] 211Represents all characters belonging to the same equivalence class as 212.Ar equiv , 213ordered by their encoded values. 214.It [#*n] 215Represents 216.Ar n 217repeated occurrences of the character represented by 218.Ar # . 219This 220expression is only valid when it occurs in 221.Ar string2 . 222If 223.Ar n 224is omitted or is zero, it is be interpreted as large enough to extend 225.Ar string2 226sequence to the length of 227.Ar string1 . 228If 229.Ar n 230has a leading zero, it is interpreted as an octal value, otherwise, 231it's interpreted as a decimal value. 232.El 233.Sh ENVIRONMENT 234The 235.Ev LANG , 236.Ev LC_ALL , 237.Ev LC_CTYPE 238and 239.Ev LC_COLLATE 240environment variables affect the execution of 241.Nm 242as described in 243.Xr environ 7 . 244.Sh EXIT STATUS 245.Ex -std 246.Sh EXAMPLES 247The following examples are shown as given to the shell: 248.Pp 249Create a list of the words in file1, one per line, where a word is taken to 250be a maximal string of letters. 251.Pp 252.D1 Li "tr -cs \*q[:alpha:]\*q \*q\en\*q < file1" 253.Pp 254Translate the contents of file1 to upper-case. 255.Pp 256.D1 Li "tr \*q[:lower:]\*q \*q[:upper:]\*q < file1" 257.Pp 258Strip out non-printable characters from file1. 259.Pp 260.D1 Li "tr -cd \*q[:print:]\*q < file1" 261.Pp 262Remove diacritical marks from all accented variants of the letter 263.Sq e : 264.Pp 265.Dl "tr \*q[=e=]\*q \*qe\*q" 266.Sh COMPATIBILITY 267System V has historically implemented character ranges using the syntax 268``[c-c]'' instead of the ``c-c'' used by historic 269.Bx 270implementations and 271standardized by POSIX. 272System V shell scripts should work under this implementation as long as 273the range is intended to map in another range, i.e. the command 274``tr [a-z] [A-Z]'' will work as it will map the ``['' character in 275.Ar string1 276to the ``['' character in 277.Ar string2 . 278However, if the shell script is deleting or squeezing characters as in 279the command ``tr -d [a-z]'', the characters ``['' and ``]'' will be 280included in the deletion or compression list which would not have happened 281under an historic System V implementation. 282Additionally, any scripts that depended on the sequence ``a-z'' to 283represent the three characters ``a'', ``-'' and ``z'' will have to be 284rewritten as ``a\e-z''. 285.Pp 286The 287.Nm 288utility has historically not permitted the manipulation of NUL bytes in 289its input and, additionally, stripped NUL's from its input stream. 290This implementation has removed this behavior as a bug. 291.Pp 292The 293.Nm 294utility has historically been extremely forgiving of syntax errors, 295for example, the 296.Fl c 297and 298.Fl s 299options were ignored unless two strings were specified. 300This implementation will not permit illegal syntax. 301.Sh STANDARDS 302The 303.Nm 304utility conforms to 305.St -p1003.1-2001 . 306.Pp 307It should be noted that the feature wherein the last character of 308.Ar string2 309is duplicated if 310.Ar string2 311has less characters than 312.Ar string1 313is permitted by POSIX but is not required. 314Shell scripts attempting to be portable to other POSIX systems should use 315the ``[#*]'' convention instead of relying on this behavior. 316The 317.Fl u 318option is an extension to the 319.St -p1003.1-2001 320standard. 321