bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sort -nu: bug or feature?


From: Paul Eggert
Subject: Re: sort -nu: bug or feature?
Date: Thu, 09 Sep 2004 16:04:14 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Stepan Kasal <address@hidden> writes:

> I think the documentation still misses one thing, see the patch below.

Thanks.  Good point.  The doc was a bit messy so I installed the
following more-ambitious patch instead.

2004-09-09  Paul Eggert  <address@hidden>

        * coreutils.texi (sort invocation): -u disables the last-resort
        comparison, too.  Revamp its description.

Index: coreutils.texi
===================================================================
RCS file: /home/eggert/coreutils/cu/doc/coreutils.texi,v
retrieving revision 1.209
retrieving revision 1.210
diff -p -u -r1.209 -r1.210
--- coreutils.texi      9 Sep 2004 04:14:49 -0000       1.209
+++ coreutils.texi      9 Sep 2004 23:02:12 -0000       1.210
@@ -3123,10 +3123,21 @@ works.
 
 @vindex LC_ALL
 @vindex LC_COLLATE
-A pair of lines is compared as follows: if any key fields have
-been specified, @command{sort} compares each pair of fields, in the
address@hidden sort stability
address@hidden sort's last-resort comparison
+A pair of lines is compared as follows:
address@hidden compares each pair of fields, in the
 order specified on the command line, according to the associated
 ordering options, until a difference is found or no fields are left.
+If no key fields are specified, @command{sort} uses a default key of
+the entire line.  Finally, as a last resort when all keys compare
+equal, @command{sort} compares entire lines as if no ordering options
+other than @option{--reverse} (@option{-r}) were specified.  The
address@hidden (@option{-s}) option disables this @dfn{last-resort
+comparison} so that lines in which all fields compare equal are left
+in their original relative order.  The @option{--unique}
+(@option{-u}) option also disables the last-resort comparison.
+
 Unless otherwise specified, all comparisons use the character collating
 sequence specified by the @env{LC_COLLATE} address@hidden you
 use a address@hidden locale (e.g., by setting @env{LC_ALL}
@@ -3139,18 +3150,6 @@ Second, it has undefined behavior if @en
 you get undefined behavior if @env{LC_CTYPE} is @code{ja_JP.PCK} but
 @env{LC_COLLATE} is @code{en_US.UTF-8}. }
 
-If any of the global options @samp{bdfgiMnr} are given but no key fields
-are specified, @command{sort} compares the entire lines according to the
-global options.
-
-Finally, as a last resort when all keys compare equal (or if no ordering
-options were specified at all), @command{sort} compares the entire lines.
-The last resort comparison honors the @option{--reverse} (@option{-r})
-global option.  The @option{--stable} (@option{-s}) option disables this
-last-resort comparison so that lines in which all fields compare equal
-are left in their original relative order.  If no fields or global
-options are specified, @option{--stable} (@option{-s}) has no effect.
-
 @sc{gnu} @command{sort} (as specified for all @sc{gnu} utilities) has no
 limit on input line length or restrictions on bytes allowed within lines.
 In addition, if the final byte of an input file is not a newline, @sc{gnu}
@@ -3349,18 +3348,11 @@ files.
 @opindex -s
 @opindex --stable
 @cindex sort stability
address@hidden disabling sort's last-resort comparison
address@hidden sort's last-resort comparison
 
-Make @command{sort} stable by disabling the last-resort
-comparison that is performed in some cases.
-By default, when lines compare equal based on command line options
-that affect ordering, those lines are ordered using
-a @dfn{last-resort comparison} that takes the entire
-line as the key and acts as if no ordering options were specified.
-But if @option{--reverse} (@option{-r}) was specified along with other
-ordering options, then the last-resort comparison does use @option{--reverse}.
-In any case, when no ordering option is specified or when only
address@hidden is specified, the last-resort comparison is not performed.
+Make @command{sort} stable by disabling its last-resort comparison.
+This option has no effect if no fields or global ordering options
+other than @option{--reverse} (@option{-R}) are specified.
 
 @item -S @var{size}
 @itemx address@hidden
@@ -3425,6 +3417,8 @@ disks and controllers.
 Normally, output only the first of a sequence of lines that compare
 equal.  For the @option{--check} (@option{-c}) option,
 check that no pair of consecutive lines compares equal.
+
+This option also disables the default last-resort comparison.
 
 The commands @code{sort -u} and @code{sort | uniq} are equivalent, but
 this equivalence does not extend to arbitrary @command{sort} options.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]