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: Andreas Schwab
Subject: Re: sort -nu: bug or feature?
Date: Wed, 08 Sep 2004 17:16:37 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3.50 (gnu/linux)

Andrew Noymer <address@hidden> writes:

> sort -nu seems to compare only the first key, which is not what a lot of 
> people expect.  I don't know if this is a bug, though.

sort -n takes the selected fields (the whole line if no -k is used) and
tries to parse a number out of each starting from the beginning of the
field, ignoring leading whitespace and discarding trailing garbage.  The
resulting numbers are the sort keys, which also decide which lines are
equivalent for -u.

> But I think most folks expect that "sort -nu" == "sort -n | uniq"

The expectation is wrong because sort -n and uniq use different sort keys.
Especially uniq is always using a string comparison.  Compare this:

$ printf "%s\n" 1 01 | sort -nu
1
$ printf "%s\n" 1 01 | sort -n | uniq
01
1

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

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