Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Apropos / Subsearch:
optional field

TR(1V)                                                                  TR(1V)

       tr - translate characters

       tr [ -cds ] [ string1 [ string2 ] ]

       /usr/5bin/tr [ -cds ] [ string1 [ string2 ] ]

       The  System  V  version  of this command is available with the System V
       software installation option.  Refer  to  for  information  on  how  to
       install optional software.

       tr  copies  the standard input to the standard output with substitution
       or deletion of selected characters.  The arguments string1 and  string2
       are  considered  sets  of  characters.   Any  input  character found in
       string1 is mapped into the  character  in  the  corresponding  position
       within  string2.   When string2 is short, it is padded to the length of
       string1 by duplicating its last character.

       In either string the notation:

       denotes a range of characters from a to b in  increasing  ASCII  order.
       The  character  \,  followed  by  1, 2 or 3 octal digits stands for the
       character whose ASCII code is given  by  those  digits.   As  with  the
       shell, the escape character \, followed by any other character, escapes
       any special meaning for that character.

       When string2 is short, characters  in  string1  with  no  corresponding
       character in string2 are not translated.

       In  either  string  the  following  abbreviation  conventions introduce
       ranges of characters or repeated characters into the strings.  Note: in
       the System V version, square brackets are required to specify a range.

       [a-z]   Stands  for the string of characters whose ASCII codes run from
               character a to character z, inclusive.

       [a*n]   Stands for n repetitions of a.  If the first digit of n is 0, n
               is  considered  octal;  otherwise, n is taken to be decimal.  A
               zero or missing n is taken to be huge; this facility is  useful
               for padding string2.

       Any combination of the options -c, -d, or -s may be used:

       -c     Complement  the set of characters in string1 with respect to the
              universe of characters whose ASCII codes  are  01  through  0377

       -d     Delete all input characters in string1.

       -s     Squeeze  all  strings  of repeated output characters that are in
              string2 to single characters.

       The following example creates a list of all the words in filename1  one
       per  line in filename2, where a word is taken to be a maximal string of
       alphabetics.  The second string is  quoted  to  protect  `\'  from  the
       shell.  012 is the ASCII code for NEWLINE.

              tr -cs A-Za-z '\012' <&lt;filename1>&gt;filename2

       In the System V version, this would be specified as:

              tr -cs '[A-Z][a-z]' '[\012*]' <&lt;filename1>&gt;filename2

       ed(1), expand(1), ascii(7)

       Will not handle ASCII NUL in string1 or string2.  tr always deletes NUL
       from input.

                               9 September 1987                         TR(1V)