Skip to content

Commit 55fe28e

Browse files
committed
(sort invocation): Add remarks about sort -u versus sort | uniq.
Prompted by a question from Andrew Noymer.
1 parent ec7650c commit 55fe28e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/coreutils.texi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3353,7 +3353,7 @@ line as the key and acts as if no ordering options were specified.
33533353
But if @option{--reverse} (@option{-r}) was specified along with other
33543354
ordering options, then the last-resort comparison does use @option{--reverse}.
33553355
In any case, when no ordering option is specified or when only
3356-
@option{--reverse} is specified, the last-resort comparison is not performed
3356+
@option{--reverse} is specified, the last-resort comparison is not performed.
33573357

33583358
@item -S @var{size}
33593359
@itemx --buffer-size=@var{size}
@@ -3419,6 +3419,12 @@ Normally, output only the first of a sequence of lines that compare
34193419
equal. For the @option{--check} (@option{-c}) option,
34203420
check that no pair of consecutive lines compares equal.
34213421

3422+
The commands @code{sort -u} and @code{sort | uniq} are equivalent, but
3423+
this equivalence does not extend to arbitrary @command{sort} options.
3424+
For example, @code{sort -n -u} inspects only the value of the initial
3425+
numeric string when checking for uniqueness, whereas @code{sort -n |
3426+
uniq} inspects the entire line. @xref{uniq invocation}.
3427+
34223428
@item -z
34233429
@itemx --zero-terminated
34243430
@opindex -z
@@ -3618,6 +3624,7 @@ lines that are not repeated, or all repeated lines.
36183624
The input need not be sorted, but repeated input lines are detected
36193625
only if they are adjacent. If you want to discard non-adjacent
36203626
duplicate lines, perhaps you want to use @code{sort -u}.
3627+
@xref{sort invocation}.
36213628

36223629
@vindex LC_COLLATE
36233630
Comparisons use the character collating sequence specified by the

0 commit comments

Comments
 (0)