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

  1.  
  2.  
  3.  
  4. SORT(1L)                                                 SORT(1L)
  5.  
  6.  
  7. NAME
  8.        sort - sort lines of text files
  9.  
  10. SYNOPSIS
  11.        sort  [-cmus] [-t separator] [-o output-file] [-T tempdir]
  12.        [-bdfiMnr] [+POS1 [-POS2]] [-k POS1[,POS2]] [file...]
  13.  
  14. DESCRIPTION
  15.        This manual page documents the GNU version of sort.   sort
  16.        sorts,  merges,  or  compares all the lines from the given
  17.        files, or the standard input if no  files  are  given.   A
  18.        file  name  of `-' means standard input.  By default, sort
  19.        writes the results to the standard output.
  20.  
  21.        sort has three modes of  operation:  sort  (the  default),
  22.        merge,  and  check  for sortedness.  The following options
  23.        change the operation mode:
  24.  
  25.        -c     Check whether the given files are  already  sorted:
  26.               if  they are not all sorted, print an error message
  27.               and exit with a status of 1.
  28.  
  29.        -m     Merge the given files by sorting them as  a  group.
  30.               Each  input  file  should  already  be individually
  31.               sorted.  It always works to sort instead of  merge;
  32.               merging  is  provided  because it is faster, in the
  33.               case where it works.
  34.  
  35.        A pair of lines is compared as follows: if any key  fields
  36.        have been specified, sort compares each pair of fields, in
  37.        the order specified on the command line, according to  the
  38.        associated  ordering  options, until a difference is found
  39.        or no fields are left.
  40.  
  41.        If any of the global options Mbdfinr are given but no  key
  42.        fields  are  specified,  sort  compares  the  entire lines
  43.        according to the global options.
  44.  
  45.        Finally, as a last resort when all keys compare equal  (or
  46.        if  no  ordering options were specified at all), sort com-
  47.        pares  the  lines  byte  by  byte  in  machine   collating
  48.        sequence.  The last resort comparison honors the -r global
  49.        option.  The -s (stable) option disables this  last-resort
  50.        comparison so that lines in which all fields compare equal
  51.        are left in their original relative order.  If  no  fields
  52.        or global options are specified, -s has no effect.
  53.  
  54.        GNU  sort  has  no limits on input line length or restric-
  55.        tions on bytes allowed within lines.  In addition, if  the
  56.        final  byte  of  an  input file is not a newline, GNU sort
  57.        silently supplies one.
  58.  
  59.        If the environment variable TMPDIR is set, sort uses it as
  60.        the  directory  in which to put temporary files instead of
  61.  
  62.  
  63.  
  64. FSF                     GNU Text Utilities                      1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SORT(1L)                                                 SORT(1L)
  71.  
  72.  
  73.        the default, /tmp.  The -T tempdir option is  another  way
  74.        to  select the directory for temporary files; it overrides
  75.        the environment variable.
  76.  
  77.        The following options affect the ordering of output lines.
  78.        They  may  be  specified globally or as part of a specific
  79.        key field.  If no key fields are specified, global options
  80.        apply  to comparison of entire lines; otherwise the global
  81.        options are inherited by key fields that  do  not  specify
  82.        any special options of their own.
  83.  
  84.        -b     Ignore  leading  blanks  when  finding sort keys in
  85.               each line.
  86.  
  87.        -d     Sort in `phone directory' order: ignore all charac-
  88.               ters  except  letters, digits and blanks when sort-
  89.               ing.
  90.  
  91.        -f     Fold lower  case  characters  into  the  equivalent
  92.               upper  case  characters  when  sorting so that, for
  93.               example, `b' is sorted the same way `B' is.
  94.  
  95.        -i     Ignore characters outside the ASCII range  040-0176
  96.               octal (inclusive) when sorting.
  97.  
  98.        -M     An  initial  string,  consisting  of  any amount of
  99.               white space, followed by three letters abbreviating
  100.               a  month name, is folded to UPPER case and compared
  101.               in the order `JAN' < `FEB' < ... < `DEC.'   Invalid
  102.               names compare low to valid names.
  103.  
  104.        -n     Compare  according  to  arithmetic value an initial
  105.               numeric string consisting of optional white  space,
  106.               an  optional  -  sign,  and  zero  or  more digits,
  107.               optionally followed by a decimal point and zero  or
  108.               more digits.
  109.  
  110.        -r     Reverse  the  result  of  comparison, so that lines
  111.               with greater key values appear earlier in the  out-
  112.               put instead of later.
  113.  
  114.        Other options are:
  115.  
  116.        -o output-file
  117.               Write output to output-file instead of to the stan-
  118.               dard output.  If output-file is one  of  the  input
  119.               files,  sort  copies  it to a temporary file before
  120.               sorting and writing the output to output-file.
  121.  
  122.        -t separator
  123.               Use character separator as the field separator when
  124.               finding  the  sort  keys in each line.  By default,
  125.               fields are separated by the empty string between  a
  126.               non-whitespace    character    and   a   whitespace
  127.  
  128.  
  129.  
  130. FSF                     GNU Text Utilities                      2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. SORT(1L)                                                 SORT(1L)
  137.  
  138.  
  139.               character.  That is to say, given the input line  `
  140.               foo  bar',  sort breaks it into fields ` foo' and `
  141.               bar'.  The field separator is not considered to  be
  142.               part  of  either  the  field preceding or the field
  143.               following it.
  144.  
  145.        -u     For the default case or the -m option, only  output
  146.               the  first  of  a  sequence  of  lines that compare
  147.               equal.  For the -c option, check that  no  pair  of
  148.               consecutive lines compares equal.
  149.  
  150.        +POS1 [-POS2]
  151.               Specify  a field within each line to use as a sort-
  152.               ing key.  The field consists of the portion of  the
  153.               line starting at POS1 and up to (but not including)
  154.               POS2 (or to the end of the  line  if  POS2  is  not
  155.               given).   The  fields  and  character positions are
  156.               numbered starting with 0.
  157.  
  158.        -k POS1[,POS2]
  159.               An alternate syntax for  specifying  sorting  keys.
  160.               The  fields  and  character  positions are numbered
  161.               starting with 1.
  162.  
  163.        A position has the form f.c, where f is the number of  the
  164.        field  to  use  and c is the number of the first character
  165.        from the beginning of the field (for +pos) or from the end
  166.        of  the previous field (for -pos).  The .c part of a posi-
  167.        tion may be omitted in which case it is taken  to  be  the
  168.        first  character  in the field.  If the -b option has been
  169.        given, the .c part of a  field  specification  is  counted
  170.        from  the first nonblank character of the field (for +pos)
  171.        or from the first nonblank character following the  previ-
  172.        ous field (for -pos).
  173.  
  174.        A  +pos  or  -pos argument may also have any of the option
  175.        letters Mbdfinr appended to it, in which case  the  global
  176.        ordering  options  are not used for that particular field.
  177.        The -b option may be independently attached to  either  or
  178.        both  of the +pos and -pos parts of a field specification,
  179.        and if it is inherited from the global options it will  be
  180.        attached  to  both.   If  a  -n or -M option is used, thus
  181.        implying a -b option, the -b option is taken to  apply  to
  182.        both  the  +pos and the -pos parts of a key specification.
  183.        Keys may span multiple fields.
  184.  
  185. COMPATIBILITY
  186.        Historical (BSD and System V) implementations of sort have
  187.        differed in their interpretation of some options, particu-
  188.        larly -b, -f, and -n.  GNU sort follows the  POSIX  behav-
  189.        ior,  which is usually (but not always!) like the System V
  190.        behavior.  According to POSIX -n  no  longer  implies  -b.
  191.        For  consistency,  -M  has  been  changed in the same way.
  192.        This may affect the  meaning  of  character  positions  in
  193.  
  194.  
  195.  
  196. FSF                     GNU Text Utilities                      3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. SORT(1L)                                                 SORT(1L)
  203.  
  204.  
  205.        field  specifications in obscure cases.  If this bites you
  206.        the fix is to add an explicit -b.
  207.  
  208. BUGS
  209.        The  different  meaning  of  field  numbers  depending  on
  210.        whether  -k is used is confusing.  It's all POSIX's fault!
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262. FSF                     GNU Text Utilities                      4
  263.  
  264.  
  265.