[BACK]Return to tr.1 CVS log [TXT][DIR] Up to [local] / src / usr.bin / tr

Annotation of src/usr.bin/tr/tr.1, Revision 1.8

1.8     ! millert     1: .\"    $OpenBSD: tr.1,v 1.7 2002/11/14 02:57:28 deraadt Exp $
1.1       deraadt     2: .\"    $NetBSD: tr.1,v 1.5 1994/12/07 08:35:13 jtc Exp $
                      3: .\"
                      4: .\" Copyright (c) 1991, 1993
                      5: .\"    The Regents of the University of California.  All rights reserved.
                      6: .\"
                      7: .\" This code is derived from software contributed to Berkeley by
                      8: .\" the Institute of Electrical and Electronics Engineers, Inc.
                      9: .\"
                     10: .\" Redistribution and use in source and binary forms, with or without
                     11: .\" modification, are permitted provided that the following conditions
                     12: .\" are met:
                     13: .\" 1. Redistributions of source code must retain the above copyright
                     14: .\"    notice, this list of conditions and the following disclaimer.
                     15: .\" 2. Redistributions in binary form must reproduce the above copyright
                     16: .\"    notice, this list of conditions and the following disclaimer in the
                     17: .\"    documentation and/or other materials provided with the distribution.
1.8     ! millert    18: .\" 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    19: .\"    may be used to endorse or promote products derived from this software
                     20: .\"    without specific prior written permission.
                     21: .\"
                     22: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     23: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     24: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25: .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     26: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32: .\" SUCH DAMAGE.
                     33: .\"
                     34: .\"     @(#)tr.1       8.1 (Berkeley) 6/6/93
                     35: .\"
                     36: .Dd June 6, 1993
                     37: .Dt TR 1
                     38: .Os
                     39: .Sh NAME
                     40: .Nm tr
                     41: .Nd translate characters
                     42: .Sh SYNOPSIS
                     43: .Nm tr
                     44: .Op Fl cs
                     45: .Ar string1 string2
                     46: .Nm tr
                     47: .Op Fl c
                     48: .Fl d
                     49: .Ar string1
                     50: .Nm tr
                     51: .Op Fl c
                     52: .Fl s
                     53: .Ar string1
                     54: .Nm tr
                     55: .Op Fl c
                     56: .Fl ds
                     57: .Ar string1 string2
                     58: .Sh DESCRIPTION
                     59: The
1.6       aaron      60: .Nm
1.1       deraadt    61: utility copies the standard input to the standard output with substitution
                     62: or deletion of selected characters.
                     63: .Pp
1.5       aaron      64: The options are as follows:
1.1       deraadt    65: .Bl -tag -width Ds
                     66: .It Fl c
                     67: Complements the set of characters in
1.4       pjanzen    68: .Ar string1 ;
                     69: for instance,
                     70: .Dq -c\ ab
                     71: includes every character except for
                     72: .Dq a
                     73: and
                     74: .Dq b .
1.1       deraadt    75: .It Fl d
                     76: The
                     77: .Fl d
                     78: option causes characters to be deleted from the input.
                     79: .It Fl s
                     80: The
                     81: .Fl s
                     82: option squeezes multiple occurrences of the characters listed in the last
                     83: operand (either
                     84: .Ar string1
                     85: or
                     86: .Ar string2 )
                     87: in the input into a single instance of the character.
                     88: This occurs after all deletion and translation is completed.
                     89: .El
                     90: .Pp
                     91: In the first synopsis form, the characters in
                     92: .Ar string1
                     93: are translated into the characters in
                     94: .Ar string2
                     95: where the first character in
                     96: .Ar string1
                     97: is translated into the first character in
                     98: .Ar string2
                     99: and so on.
                    100: If
                    101: .Ar string1
                    102: is longer than
                    103: .Ar string2 ,
                    104: the last character found in
                    105: .Ar string2
                    106: is duplicated until
                    107: .Ar string1
                    108: is exhausted.
                    109: .Pp
                    110: In the second synopsis form, the characters in
                    111: .Ar string1
                    112: are deleted from the input.
                    113: .Pp
                    114: In the third synopsis form, the characters in
                    115: .Ar string1
                    116: are compressed as described for the
                    117: .Fl s
                    118: option.
                    119: .Pp
                    120: In the fourth synopsis form, the characters in
                    121: .Ar string1
                    122: are deleted from the input, and the characters in
                    123: .Ar string2
                    124: are compressed as described for the
                    125: .Fl s
                    126: option.
                    127: .Pp
                    128: The following conventions can be used in
                    129: .Ar string1
                    130: and
                    131: .Ar string2
                    132: to specify sets of characters:
                    133: .Bl -tag -width [:equiv:]
                    134: .It character
                    135: Any character not described by one of the following conventions
                    136: represents itself.
                    137: .It \eoctal
1.4       pjanzen   138: A backslash followed by 1, 2, or 3 octal digits represents a character
1.1       deraadt   139: with that encoded value.
                    140: To follow an octal sequence with a digit as a character, left zero-pad
                    141: the octal sequence to the full 3 octal digits.
                    142: .It \echaracter
                    143: A backslash followed by certain special characters maps to special
                    144: values.
1.6       aaron     145: .Pp
1.1       deraadt   146: .Bl -column
                    147: .It \ea        <alert character>
                    148: .It \eb        <backspace>
                    149: .It \ef        <form-feed>
                    150: .It \en        <newline>
                    151: .It \er        <carriage return>
                    152: .It \et        <tab>
                    153: .It \ev        <vertical tab>
                    154: .El
1.6       aaron     155: .Pp
1.1       deraadt   156: A backslash followed by any other character maps to that character.
                    157: .It c-c
                    158: Represents the range of characters between the range endpoints, inclusively.
                    159: .It [:class:]
                    160: Represents all characters belonging to the defined character class.
                    161: Class names are:
1.6       aaron     162: .Pp
1.1       deraadt   163: .Bl -column
                    164: .It alnum      <alphanumeric characters>
                    165: .It alpha      <alphabetic characters>
                    166: .It blank      <blank characters>
                    167: .It cntrl      <control characters>
                    168: .It digit      <numeric characters>
                    169: .It graph      <graphic characters>
                    170: .It lower      <lower-case alphabetic characters>
                    171: .It print      <printable characters>
                    172: .It punct      <punctuation characters>
                    173: .It space      <space characters>
                    174: .It upper      <upper-case characters>
                    175: .It xdigit     <hexadecimal characters>
                    176: .El
                    177: .Pp
                    178: \." All classes may be used in
                    179: \." .Ar string1 ,
                    180: \." and in
                    181: \." .Ar string2
                    182: \." when both the
                    183: \." .Fl d
                    184: \." and
                    185: \." .Fl s
                    186: \." options are specified.
                    187: \." Otherwise, only the classes ``upper'' and ``lower'' may be used in
                    188: \." .Ar string2
                    189: \." and then only when the corresponding class (``upper'' for ``lower''
                    190: \." and vice-versa) is specified in the same relative position in
                    191: \." .Ar string1 .
                    192: \." .Pp
1.4       pjanzen   193: With the exception of the
                    194: .Dq upper
                    195: and
                    196: .Dq lower
                    197: classes, characters
1.1       deraadt   198: in the classes are in unspecified order.
1.4       pjanzen   199: In the
                    200: .Dq upper
                    201: and
                    202: .Dq lower
                    203: classes, characters are entered in
1.1       deraadt   204: ascending order.
                    205: .Pp
                    206: For specific information as to which ASCII characters are included
                    207: in these classes, see
                    208: .Xr ctype 3
                    209: and related manual pages.
                    210: .It [=equiv=]
                    211: Represents all characters or collating (sorting) elements belonging to
                    212: the same equivalence class as
                    213: .Ar equiv .
                    214: If
                    215: there is a secondary ordering within the equivalence class, the characters
                    216: are ordered in ascending sequence.
1.4       pjanzen   217: Otherwise, they are ordered after their encoded values.
                    218: An example of an equivalence class might be
                    219: .Dq c
                    220: and
                    221: .Dq ch
                    222: in Spanish;
1.1       deraadt   223: English has no equivalence classes.
                    224: .It [#*n]
                    225: Represents
                    226: .Ar n
                    227: repeated occurrences of the character represented by
                    228: .Ar # .
                    229: This
                    230: expression is only valid when it occurs in
                    231: .Ar string2 .
                    232: If
                    233: .Ar n
                    234: is omitted or is zero, it is be interpreted as large enough to extend
                    235: .Ar string2
                    236: sequence to the length of
                    237: .Ar string1 .
                    238: If
                    239: .Ar n
1.4       pjanzen   240: has a leading zero, it is interpreted as an octal value; otherwise,
1.1       deraadt   241: it's interpreted as a decimal value.
                    242: .El
                    243: .Pp
                    244: The
1.6       aaron     245: .Nm
1.3       aaron     246: utility exits 0 on success or >0 if an error occurred.
1.1       deraadt   247: .Sh EXAMPLES
                    248: The following examples are shown as given to the shell:
1.6       aaron     249: .Pp
1.1       deraadt   250: Create a list of the words in file1, one per line, where a word is taken to
                    251: be a maximal string of letters.
1.6       aaron     252: .Pp
1.7       deraadt   253: .D1 Li "$ tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
1.6       aaron     254: .Pp
1.1       deraadt   255: Translate the contents of file1 to upper-case.
1.6       aaron     256: .Pp
1.7       deraadt   257: .D1 Li "$ tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
1.6       aaron     258: .Pp
1.1       deraadt   259: Strip out non-printable characters from file1.
1.6       aaron     260: .Pp
1.7       deraadt   261: .D1 Li "$ tr -cd \*q[:print:]\*q < file1"
1.6       aaron     262: .Sh SEE ALSO
                    263: .Xr sed 1
1.1       deraadt   264: .Sh COMPATIBILITY
                    265: System V has historically implemented character ranges using the syntax
1.4       pjanzen   266: .Dq [c-c]
                    267: instead of the
                    268: .Dq c-c
                    269: used by historic BSD implementations and
1.1       deraadt   270: standardized by POSIX.
                    271: System V shell scripts should work under this implementation as long as
1.6       aaron     272: the range is intended to map in another range, i.e., the command
1.4       pjanzen   273: .Dq tr\ [a-z]\ [A-Z]
                    274: will work as it will map the
                    275: .Dq [
                    276: character in
                    277: .Ar string1
                    278: to the
                    279: .Dq [
                    280: character in
1.3       aaron     281: .Ar string2 .
1.1       deraadt   282: However, if the shell script is deleting or squeezing characters as in
1.4       pjanzen   283: the command
                    284: .Dq tr\ -d\ [a-z] ,
                    285: the characters
                    286: .Dq [
                    287: and
                    288: .Dq \]
                    289: will be
                    290: included in the deletion or compression list, which would not have happened
1.1       deraadt   291: under an historic System V implementation.
1.4       pjanzen   292: Additionally, any scripts that depended on the sequence
                    293: .Dq a-z
                    294: to represent the three characters
                    295: .Dq a ,
                    296: .Dq - ,
                    297: and
                    298: .Dq z
                    299: will have to be rewritten as
                    300: .Dq a\e-z .
1.1       deraadt   301: .Pp
                    302: The
1.6       aaron     303: .Nm
1.1       deraadt   304: utility has historically not permitted the manipulation of NUL bytes in
1.4       pjanzen   305: its input and, additionally, has stripped NUL's from its input stream.
1.1       deraadt   306: This implementation has removed this behavior as a bug.
                    307: .Pp
                    308: The
1.6       aaron     309: .Nm
1.4       pjanzen   310: utility has historically been extremely forgiving of syntax errors:
1.1       deraadt   311: for example, the
                    312: .Fl c
                    313: and
                    314: .Fl s
                    315: options were ignored unless two strings were specified.
                    316: This implementation will not permit illegal syntax.
                    317: .Sh STANDARDS
                    318: The
1.6       aaron     319: .Nm
1.1       deraadt   320: utility is expected to be
                    321: .St -p1003.2
                    322: compatible.
                    323: It should be noted that the feature wherein the last character of
                    324: .Ar string2
                    325: is duplicated if
                    326: .Ar string2
                    327: has less characters than
                    328: .Ar string1
                    329: is permitted by POSIX but is not required.
                    330: Shell scripts attempting to be portable to other POSIX systems should use
1.4       pjanzen   331: the
                    332: .Dq [#*]
                    333: convention instead of relying on this behavior.