home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / man / cat1 / sort.0 < prev    next >
Text File  |  1993-12-07  |  9KB  |  265 lines

  1.  
  2.  
  3.  
  4. SORT(1L)                                                 SORT(1L)
  5.  
  6.  
  7. NNAAMMEE
  8.        sort - sort lines of text files
  9.  
  10. SSYYNNOOPPSSIISS
  11.        ssoorrtt  [-cmus] [-t separator] [-o output-file] [-T tempdir]
  12.        [-bdfiMnr] [+POS1 [-POS2]] [-k POS1[,POS2]] [file...]
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.        This manual page documents the GNU version of ssoorrtt.   ssoorrtt
  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, ssoorrtt
  19.        writes the results to the standard output.
  20.  
  21.        ssoorrtt 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, ssoorrtt 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 _M_b_d_f_i_n_r are given but no  key
  42.        fields  are  specified,  ssoorrtt  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), ssoorrtt 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  ssoorrtt  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 ssoorrtt
  57.        silently supplies one.
  58.  
  59.        If the environment variable TTMMPPDDIIRR is set, ssoorrtt 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 _t_e_m_p_d_i_r 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 _o_u_t_p_u_t_-_f_i_l_e
  117.               Write output to _o_u_t_p_u_t_-_f_i_l_e instead of to the stan-
  118.               dard output.  If _o_u_t_p_u_t_-_f_i_l_e is one  of  the  input
  119.               files,  ssoorrtt  copies  it to a temporary file before
  120.               sorting and writing the output to _o_u_t_p_u_t_-_f_i_l_e.
  121.  
  122.        _-_t _s_e_p_a_r_a_t_o_r
  123.               Use character _s_e_p_a_r_a_t_o_r 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',  ssoorrtt 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.        _+_P_O_S_1 _[_-_P_O_S_2_]
  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 _P_O_S_1_[_,_P_O_S_2_]
  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 _+_p_o_s) or from the end
  166.        of  the previous field (for _-_p_o_s).  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 _+_p_o_s)
  171.        or from the first nonblank character following the  previ-
  172.        ous field (for _-_p_o_s).
  173.  
  174.        A  _+_p_o_s  or  _-_p_o_s argument may also have any of the option
  175.        letters _M_b_d_f_i_n_r 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 _+_p_o_s and _-_p_o_s 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  _+_p_o_s and the _-_p_o_s parts of a