[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.21

1.21    ! millert     1: .\"    $OpenBSD: tr.1,v 1.20 2013/08/14 08:39:27 jmc 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: .\"
1.21    ! millert    36: .Dd $Mdocdate: August 14 2013 $
1.1       deraadt    37: .Dt TR 1
                     38: .Os
                     39: .Sh NAME
                     40: .Nm tr
                     41: .Nd translate characters
                     42: .Sh SYNOPSIS
                     43: .Nm tr
1.21    ! millert    44: .Op Fl Ccs
1.1       deraadt    45: .Ar string1 string2
                     46: .Nm tr
1.21    ! millert    47: .Op Fl Cc
1.1       deraadt    48: .Fl d
                     49: .Ar string1
                     50: .Nm tr
1.21    ! millert    51: .Op Fl Cc
1.1       deraadt    52: .Fl s
                     53: .Ar string1
                     54: .Nm tr
1.21    ! millert    55: .Op Fl Cc
1.1       deraadt    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
1.21    ! millert    66: .It Fl C
1.1       deraadt    67: Complements the set of characters in
1.4       pjanzen    68: .Ar string1 ;
                     69: for instance,
1.21    ! millert    70: .Dq -C\ ab
1.4       pjanzen    71: includes every character except for
                     72: .Dq a
                     73: and
                     74: .Dq b .
1.21    ! millert    75: .It Fl c
        !            76: The same as
        !            77: .Fl C .
1.1       deraadt    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: .El
                     93: .Pp
                     94: In the first synopsis form, the characters in
                     95: .Ar string1
                     96: are translated into the characters in
                     97: .Ar string2
                     98: where the first character in
                     99: .Ar string1
                    100: is translated into the first character in
                    101: .Ar string2
                    102: and so on.
                    103: If
                    104: .Ar string1
                    105: is longer than
                    106: .Ar string2 ,
                    107: the last character found in
                    108: .Ar string2
                    109: is duplicated until
                    110: .Ar string1
                    111: is exhausted.
                    112: .Pp
                    113: In the second synopsis form, the characters in
                    114: .Ar string1
                    115: are deleted from the input.
                    116: .Pp
                    117: In the third synopsis form, the characters in
                    118: .Ar string1
                    119: are compressed as described for the
                    120: .Fl s
                    121: option.
                    122: .Pp
                    123: In the fourth synopsis form, the characters in
                    124: .Ar string1
                    125: are deleted from the input, and the characters in
                    126: .Ar string2
                    127: are compressed as described for the
                    128: .Fl s
                    129: option.
                    130: .Pp
                    131: The following conventions can be used in
                    132: .Ar string1
                    133: and
                    134: .Ar string2
                    135: to specify sets of characters:
                    136: .Bl -tag -width [:equiv:]
                    137: .It character
                    138: Any character not described by one of the following conventions
                    139: represents itself.
                    140: .It \eoctal
1.4       pjanzen   141: A backslash followed by 1, 2, or 3 octal digits represents a character
1.1       deraadt   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.
                    145: .It \echaracter
                    146: A backslash followed by certain special characters maps to special
                    147: values.
1.6       aaron     148: .Pp
1.19      jmc       149: .Bl -tag -width "nn" -offset indent -compact
                    150: .It \ea
                    151: <alert character>
                    152: .It \eb
                    153: <backspace>
                    154: .It \ef
                    155: <form-feed>
                    156: .It \en
                    157: <newline>
                    158: .It \er
                    159: <carriage return>
                    160: .It \et
                    161: <tab>
                    162: .It \ev
                    163: <vertical tab>
1.1       deraadt   164: .El
1.6       aaron     165: .Pp
1.1       deraadt   166: A backslash followed by any other character maps to that character.
                    167: .It c-c
                    168: Represents the range of characters between the range endpoints, inclusively.
                    169: .It [:class:]
                    170: Represents all characters belonging to the defined character class.
                    171: Class names are:
1.6       aaron     172: .Pp
1.19      jmc       173: .Bl -tag -width "xdigit" -offset indent -compact
                    174: .It alnum
                    175: <alphanumeric characters>
                    176: .It alpha
                    177: <alphabetic characters>
                    178: .It blank
                    179: <blank characters>
                    180: .It cntrl
                    181: <control characters>
                    182: .It digit
                    183: <numeric characters>
                    184: .It graph
                    185: <graphic characters>
                    186: .It lower
                    187: <lower-case alphabetic characters>
                    188: .It print
                    189: <printable characters>
                    190: .It punct
                    191: <punctuation characters>
                    192: .It space
                    193: <space characters>
                    194: .It upper
                    195: <upper-case characters>
                    196: .It xdigit
                    197: <hexadecimal characters>
1.1       deraadt   198: .El
                    199: .Pp
1.15      deraadt   200: .\" All classes may be used in
                    201: .\" .Ar string1 ,
                    202: .\" and in
                    203: .\" .Ar string2
                    204: .\" when both the
                    205: .\" .Fl d
                    206: .\" and
                    207: .\" .Fl s
                    208: .\" options are specified.
                    209: .\" Otherwise, only the classes ``upper'' and ``lower'' may be used in
                    210: .\" .Ar string2
                    211: .\" and then only when the corresponding class (``upper'' for ``lower''
                    212: .\" and vice-versa) is specified in the same relative position in
                    213: .\" .Ar string1 .
                    214: .\" .Pp
1.4       pjanzen   215: With the exception of the
                    216: .Dq upper
                    217: and
                    218: .Dq lower
                    219: classes, characters
1.1       deraadt   220: in the classes are in unspecified order.
1.4       pjanzen   221: In the
                    222: .Dq upper
                    223: and
                    224: .Dq lower
                    225: classes, characters are entered in
1.1       deraadt   226: ascending order.
                    227: .Pp
                    228: For specific information as to which ASCII characters are included
                    229: in these classes, see
                    230: .Xr ctype 3
                    231: and related manual pages.
                    232: .It [=equiv=]
                    233: Represents all characters or collating (sorting) elements belonging to
                    234: the same equivalence class as
                    235: .Ar equiv .
                    236: If
                    237: there is a secondary ordering within the equivalence class, the characters
                    238: are ordered in ascending sequence.
1.4       pjanzen   239: Otherwise, they are ordered after their encoded values.
                    240: An example of an equivalence class might be
                    241: .Dq c
                    242: and
                    243: .Dq ch
                    244: in Spanish;
1.1       deraadt   245: English has no equivalence classes.
                    246: .It [#*n]
                    247: Represents
                    248: .Ar n
                    249: repeated occurrences of the character represented by
                    250: .Ar # .
                    251: This
                    252: expression is only valid when it occurs in
                    253: .Ar string2 .
                    254: If
                    255: .Ar n
1.18      jmc       256: is omitted or is zero, it is interpreted as large enough to extend the
1.1       deraadt   257: .Ar string2
                    258: sequence to the length of
                    259: .Ar string1 .
                    260: If
                    261: .Ar n
1.4       pjanzen   262: has a leading zero, it is interpreted as an octal value; otherwise,
1.1       deraadt   263: it's interpreted as a decimal value.
                    264: .El
1.17      jmc       265: .Sh EXIT STATUS
1.12      sobrado   266: .Ex -std tr
1.1       deraadt   267: .Sh EXAMPLES
                    268: The following examples are shown as given to the shell:
1.6       aaron     269: .Pp
1.1       deraadt   270: Create a list of the words in file1, one per line, where a word is taken to
                    271: be a maximal string of letters.
1.6       aaron     272: .Pp
1.7       deraadt   273: .D1 Li "$ tr -cs \*q[:alpha:]\*q \*q\en\*q < file1"
1.6       aaron     274: .Pp
1.1       deraadt   275: Translate the contents of file1 to upper-case.
1.6       aaron     276: .Pp
1.7       deraadt   277: .D1 Li "$ tr \*q[:lower:]\*q \*q[:upper:]\*q < file1"
1.6       aaron     278: .Pp
1.1       deraadt   279: Strip out non-printable characters from file1.
1.6       aaron     280: .Pp
1.7       deraadt   281: .D1 Li "$ tr -cd \*q[:print:]\*q < file1"
1.6       aaron     282: .Sh SEE ALSO
                    283: .Xr sed 1
1.9       jmc       284: .Sh STANDARDS
1.10      jmc       285: The
                    286: .Nm
                    287: utility is compliant with the
1.13      jmc       288: .St -p1003.1-2008
1.21    ! millert   289: specification,
        !           290: except that the
        !           291: .Fl C
        !           292: option behaves the same as the
        !           293: .Fl c
        !           294: option since
        !           295: .Nm
        !           296: is not locale-aware.
1.10      jmc       297: .Pp
1.1       deraadt   298: System V has historically implemented character ranges using the syntax
1.4       pjanzen   299: .Dq [c-c]
                    300: instead of the
                    301: .Dq c-c
1.20      jmc       302: used by historic
                    303: .Bx
                    304: implementations and
1.1       deraadt   305: standardized by POSIX.
                    306: System V shell scripts should work under this implementation as long as
1.6       aaron     307: the range is intended to map in another range, i.e., the command
1.4       pjanzen   308: .Dq tr\ [a-z]\ [A-Z]
                    309: will work as it will map the
1.16      schwarze  310: .Dq \&[
1.4       pjanzen   311: character in
                    312: .Ar string1
                    313: to the
1.16      schwarze  314: .Dq \&[
1.4       pjanzen   315: character in
1.3       aaron     316: .Ar string2 .
1.1       deraadt   317: However, if the shell script is deleting or squeezing characters as in
1.4       pjanzen   318: the command
                    319: .Dq tr\ -d\ [a-z] ,
                    320: the characters
1.16      schwarze  321: .Dq \&[
1.4       pjanzen   322: and
                    323: .Dq \]
                    324: will be
                    325: included in the deletion or compression list, which would not have happened
1.1       deraadt   326: under an historic System V implementation.
1.4       pjanzen   327: Additionally, any scripts that depended on the sequence
                    328: .Dq a-z
                    329: to represent the three characters
                    330: .Dq a ,
                    331: .Dq - ,
                    332: and
                    333: .Dq z
                    334: will have to be rewritten as
                    335: .Dq a\e-z .
1.1       deraadt   336: .Pp
                    337: The
1.6       aaron     338: .Nm
1.1       deraadt   339: utility has historically not permitted the manipulation of NUL bytes in
1.4       pjanzen   340: its input and, additionally, has stripped NUL's from its input stream.
1.1       deraadt   341: This implementation has removed this behavior as a bug.
                    342: .Pp
                    343: The
1.6       aaron     344: .Nm
1.4       pjanzen   345: utility has historically been extremely forgiving of syntax errors:
1.1       deraadt   346: for example, the
                    347: .Fl c
                    348: and
                    349: .Fl s
                    350: options were ignored unless two strings were specified.
                    351: This implementation will not permit illegal syntax.
1.9       jmc       352: .Pp
1.1       deraadt   353: It should be noted that the feature wherein the last character of
                    354: .Ar string2
                    355: is duplicated if
                    356: .Ar string2
                    357: has less characters than
                    358: .Ar string1
                    359: is permitted by POSIX but is not required.
                    360: Shell scripts attempting to be portable to other POSIX systems should use
1.4       pjanzen   361: the
                    362: .Dq [#*]
                    363: convention instead of relying on this behavior.