Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ tr(1) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed

sh

ascii

tr

PURPOSE

     Translates characters.

SYNOPSIS
     tr [ -cdsA ] [ string1 [ string2 ] ]


DESCRIPTION

     The tr command copies  characters from the standard input
     to the  standard output with substitution  or deletion of
     selected characters.   Input characters from  string1 are
     replaced  with the  corresponding characters  in string2.
     tr  cannot  handle an  ASCII  NUL  (\000) in  string1  or
     string2; it always deletes NUL from the input.

     Abbreviations  that can  be used  to introduce  ranges of
     characters or repeated characters are:

     [a-z]   Stands  for a  string of  characters whose  ASCII
             codes run from character a to character z, inclu-
             sive.
     [a*num] Stands for num repetitions  of a.  num is consid-
             ered to be  in decimal unless the  first digit of
             num is 0; then it is considered to be in octal.

     Use the escape character  \ (backslash) to remove special
     meaning from any  character in a string.  Use  the \ fol-
     lowed by 1, 2, or 3 octal  digits for the ASCII code of a
     character.

FLAGS

     -A Translates on a byte-by-byte  basis.  When you specify
        this flag, tr does not support extended characters.
     -c Complements (inverts) the set of characters in string1
        with respect to the universe of characters whose ASCII
        codes are  001 through 377  octal, if you  specify -A,
        and all characters, if you do not specify -A.
     -d Deletes all input characters in string1.
     -s Changes characters that are repeated output characters
        in string2 into single characters.

EXAMPLES

     1.  To translate braces into parentheses:

           tr  '{}'  '()'  <textfile  >newfile

         This translates each "{" to  "(" and each "}" to ")".
         All other characters remain unchanged.
     2.  To translate lowercase characters to uppercase:

           tr  '[a-z]'  '[A-Z]'  <textfile  >newfile

     3.  This is what happens if  the strings are not the same
         length:

           tr  '[0-9]'  '#'  <textfile  >newfile

         This translates each "0" to a # (number sign).

         Note:  If the two character  strings are not the same
         length, then  the extra characters in  the longer one
         are ignored.
     4.  To translate each digit to a #:

           tr  '[0-9]'  '[#*]'   <textfile  >newfile

         The * tells  tr to repeat the # enough  times to make
         the second string as long as the first one.
     5.  To translate each string of digits to a single num:

           tr  -s  '[0-9]'  '[#*]'   <textfile  >newfile

     6.   To translate all ASCII characters that are not spec-
         ified:

           tr  -c  '[  -~]'  '[A-_]?'   <textfile  >newfile

          This translates each non-printing ASCII character to
         the corresponding  control key letter  ("\001" trans-
         lates  to  "A",  "\002"  to "B",  etc.).   ASCII  DEL
         ("\177"),  the character  that  follows "~"  (tilde),
         translates to ?.
     7.  To create a list of the words in a file:

           tr  -cs  '[a-z][A-Z]'  '[\012*]'   <textfile  >newfile

         This translates each  string of nonalphabetic charac-
         ters to a single new-line character.  The result is a
         list of  all the  words in  "textfile", one  word per
         line.

RELATED INFORMATION

     The following commands:  "ed" and "sh."

     The ascii  file in AIX Operating  System Technical Refer-
     ence.

     The "Overview of International Character Support" in Man-
     aging the AIX Operating System.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026