home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / doc / tr.man < prev    next >
Text File  |  1993-06-13  |  11KB  |  331 lines

  1.  
  2.  
  3.  
  4. TR(1L)                                                     TR(1L)
  5.  
  6.  
  7. NAME
  8.        tr - translate or delete characters
  9.  
  10. SYNOPSIS
  11.        tr   [-cst]  [--complement]  [--squeeze-repeats]  [--trun-
  12.        cate-set1] string1 string2
  13.        tr {-s,--squeeze-repeats} [-c] [--complement] string1
  14.        tr {-d,--delete} [-c] string1
  15.        tr {-d,--delete}  {-s,--squeeze-repeats}  [-c]  [--comple-
  16.        ment] string1 string2
  17.  
  18.        GNU tr also accepts the --help and --version options.
  19.  
  20. DESCRIPTION
  21.        This  manual  page  documents  the  GNU version of tr.  tr
  22.        copies the standard input to the standard output, perform-
  23.        ing one of the following operations:
  24.  
  25.               o  translate, and optionally squeeze repeated char-
  26.               acters in the result
  27.               o squeeze repeated characters
  28.               o delete characters
  29.               o delete characters, then squeeze repeated  charac-
  30.               ters from the result.
  31.  
  32.        The  string1  and  (if  given)  string2  arguments  define
  33.        ordered sets of characters, referred to below as set1  and
  34.        set2.   These sets are the characters of the input that tr
  35.        operates on.  The --complement (-c) option  replaces  set1
  36.        with its complement (all of the characters that are not in
  37.        set1).
  38.  
  39.    SPECIFYING SETS OF CHARACTERS
  40.        The format of the string1 and string2 arguments  resembles
  41.        the  format  of regular expressions; however, they are not
  42.        regular expressions, only lists of characters.  Most char-
  43.        acters  simply  represent themselves in these strings, but
  44.        the strings can contain the shorthands listed  below,  for
  45.        convenience.   Some of them can be used only in string1 or
  46.        string2, as noted below.
  47.  
  48.        Backslash escapes.  A backslash followed  by  a  character
  49.        not listed below causes an error message.
  50.  
  51.        \a     Control-G.
  52.  
  53.        \b     Control-H.
  54.  
  55.        \f     Control-L.
  56.  
  57.        \n     Control-J.
  58.  
  59.        \r     Control-M.
  60.  
  61.  
  62.  
  63.  
  64. FSF                     GNU Text Utilities                      1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. TR(1L)                                                     TR(1L)
  71.  
  72.  
  73.        \t     Control-I.
  74.  
  75.        \v     Control-K.
  76.  
  77.        \ooo   The character with the value given by ooo, which is
  78.               1 to 3 octal digits.
  79.  
  80.        \\     A backslash.
  81.  
  82.        Ranges.  The notation `m-n' expands to all of the  charac-
  83.        ters  from m through n, in ascending order.  m should col-
  84.        late before n; if it doesn't, an  error  results.   As  an
  85.        example,  `0-9' is the same as `0123456789'.  Although GNU
  86.        tr does not support the System V syntax that  uses  square
  87.        brackets to enclose ranges, translations specified in that
  88.        format will still work as long as the brackets in  string1
  89.        correspond to identical brackets in string2.
  90.  
  91.        Repeated  characters.   The  notation  `[c*n]'  in string2
  92.        expands to n copies of character c.  Thus, `[y*6]' is  the
  93.        same  as `yyyyyy'.  The notation `[c*]' in string2 expands
  94.        to as many copies of c as are needed to make set2 as  long
  95.        as  set1.   If  n  begins  with  a 0, it is interpreted in
  96.        octal, otherwise in decimal.
  97.  
  98.        Character classes.  The notation `[:class-name:]'  expands
  99.        to  all  of the characters in the (predefined) class named
  100.        class-name.  The characters expand in no particular order,
  101.        except  for  the `upper' and `lower' classes, which expand
  102.        in  ascending  order.   When   the   --delete   (-d)   and
  103.        --squeeze-repeats (-s) options are both given, any charac-
  104.        ter class can be used in  string2.   Otherwise,  only  the
  105.        character  classes  `lower'  and  `upper'  are accepted in
  106.        string2, and then  only  if  the  corresponding  character
  107.        class  (`upper' and `lower', respectively) is specified in
  108.        the same relative position in string1.  Doing this  speci-
  109.        fies case conversion.  The class names are given below; an
  110.        error results when an invalid class name is given.
  111.  
  112.        alnum  Letters and digits.
  113.  
  114.        alpha  Letters.
  115.  
  116.        blank  Horizontal whitespace.
  117.  
  118.        cntrl  Control characters.
  119.  
  120.        digit  Digits.
  121.  
  122.        graph  Printable characters, not including space.
  123.  
  124.        lower  Lowercase letters.
  125.  
  126.        print  Printable characters, including space.
  127.  
  128.  
  129.  
  130. FSF                     GNU Text Utilities                      2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. TR(1L)                                                     TR(1L)
  137.  
  138.  
  139.        punct  Punctuation characters.
  140.  
  141.        space  Horizontal or vertical whitespace.
  142.  
  143.        upper  Uppercase letters.
  144.  
  145.        xdigit Hexadecimal digits.
  146.  
  147.        Equivalence classes.  The syntax `[=c=]' expands to all of
  148.        the  characters that are equivalent to c, in no particular
  149.        order.   Equivalence  classes  are  a   recent   invention
  150.        intended  to  support  non-English  alphabets.   But there
  151.        seems to be no standard way to define  them  or  determine
  152.        their contents.  Therefore, they are not fully implemented
  153.        in GNU tr; each  character's  equivalence  class  consists
  154.        only  of  that  character, which makes this a useless con-
  155.        struction currently.
  156.  
  157.    TRANSLATING
  158.        tr performs translation when string1 and string2 are  both
  159.        given  and  the  --delete  (-d)  option  is not given.  tr
  160.        translates each character of its input that is in set1  to
  161.        the  corresponding  character  in set2.  Characters not in
  162.        set1 are  passed  through  unchanged.   When  a  character
  163.        appears more than once in set1 and the corresponding char-
  164.        acters in set2 are not all the same, only the final one is
  165.        used.  For example, these two commands are equivalent:
  166.               tr aaa xyz
  167.               tr a z
  168.  
  169.        A  common  use of tr is to convert lowercase characters to
  170.        uppercase.  This can be done in many ways.  Here are three
  171.        of them:
  172.               tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
  173.               tr a-z A-Z
  174.               tr '[:lower:]' '[:upper:]'
  175.  
  176.        When  tr  is  performing translation, set1 and set2 should
  177.        normally have the same length.  If set1  is  shorter  than
  178.        set2, the extra characters at the end of set2 are ignored.
  179.  
  180.        On the other hand, making set1 longer  than  set2  is  not
  181.        portable;  POSIX.2  says that the result is undefined.  In
  182.        this situation, the BSD tr pads set2 to the length of set1
  183.        by  repeating  the last character of set2 as many times as
  184.        necessary.  The System V tr truncates set1 to  the  length
  185.        of set2.
  186.  
  187.        By default, GNU tr handles this case like the BSD tr does.
  188.        When the --truncate-set1 (-t) option is given, GNU tr han-
  189.        dles  this case like the System V tr instead.  This option
  190.        is ignored for operations other than translation.
  191.  
  192.        Acting like the System  V  tr  in  this  case  breaks  the
  193.  
  194.  
  195.  
  196. FSF                     GNU Text Utilities                      3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. TR(1L)                                                     TR(1L)
  203.  
  204.  
  205.        relatively common BSD idiom:
  206.               tr -cs A-Za-z0-9 '\012'
  207.        because  it converts only zero bytes (the first element in
  208.        the  complement   of   set1),   rather   than   all   non-
  209.        alphanumerics, to newlines.
  210.  
  211.    SQUEEZING REPEATS AND DELETING
  212.        When  given  just the --delete (-d) option, tr removes any
  213.        input characters that are in set1.
  214.  
  215.        When given just  the  --squeeze-repeats  (-s)  option,  tr
  216.        replaces  each input sequence of a repeated character that
  217.        is in set1 with a single occurrence of that character.
  218.  
  219.        When given both the  --delete  and  the  --squeeze-repeats
  220.        options,  tr first performs any deletions using set1, then
  221.        squeezes repeats from any remaining characters using set2.
  222.  
  223.        The  --squeeze-repeats option may also be used when trans-
  224.        lating, in which case tr first performs translation,  then
  225.        squeezes repeats from any remaining characters using set2.
  226.  
  227.        Here are some examples to illustrate various  combinations
  228.        of options:
  229.  
  230.        Remove all zero bytes:
  231.               tr -d '\000'
  232.  
  233.        Put  all  words on lines by themselves.  This converts all
  234.        non-alphanumeric characters  to  newlines,  then  squeezes
  235.        each string of repeated newlines into a single newline:
  236.               tr -cs '[a-zA-Z0-9]' '[\n*]'
  237.  
  238.        Convert  each  sequence  of  repeated newlines to a single
  239.        newline:
  240.               tr -s '\n'
  241.  
  242.        GNU tr also accepts the following options in any  combina-
  243.        tion with the others.
  244.  
  245.        --help Print a usage message and exit with a non-zero sta-
  246.               tus.
  247.  
  248.        --version
  249.               Print version information on  standard  error  then
  250.               exit.
  251.  
  252.    WARNING MESSAGES
  253.        Setting the environment variable POSIXLY_CORRECT turns off
  254.        several warning and error messages, for strict  compliance
  255.        with  POSIX.2.  The messages normally occur in the follow-
  256.        ing circumstances:
  257.  
  258.        1.    When   the   --delete   option    is    given    but
  259.  
  260.  
  261.  
  262. FSF                     GNU Text Utilities                      4
  263.  
  264.  
  265.  
  266.  
  267.  
  268. TR(1L)                                                     TR(1L)
  269.  
  270.  
  271.        --squeeze-repeats  is not, and string2 is given, GNU tr by
  272.        default prints a usage message and exits, because  string2
  273.        would  not  be  used.   The  POSIX specification says that
  274.        string2 must be ignored in this case.   Silently  ignoring
  275.        arguments is a bad idea.
  276.  
  277.        2.  When an ambiguous octal escape is given.  For example,
  278.        \400 is actually \40 followed by the digit 0, because  the
  279.        value 400 octal does not fit into a single byte.
  280.  
  281.        Note that GNU tr does not provide complete BSD or System V
  282.        compatibility.  For example, there is no option to disable
  283.        interpretation  of  the POSIX constructs [:alpha:], [=c=],
  284.        and [c*10].  Also, GNU tr does not delete zero bytes auto-
  285.        matically, unlike traditional UNIX versions, which provide
  286.        no way to preserve zero bytes.
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328. FSF                     GNU Text Utilities                      5
  329.  
  330.  
  331.