bug-coreutils
[Top][All Lists]
Advanced

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

Re: Sort Bug


From: Andreas Schwab
Subject: Re: Sort Bug
Date: Wed, 29 Oct 2003 22:35:46 +0100
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3.50 (gnu/linux)

Paul Eggert <address@hidden> writes:

> address@hidden writes:
>
>> address@hidden>ls -l | sort -k 5
>> total 3165056
>> -rw-r--r--    1 robertd  users         678 Jul 10 15:15 
>> rejected_tms_inbox.dmp.gz
>> -rw-r--r--    1 robertd  users         840 Jul 21 13:50 161examples.dmp.gz
>> -rw-r--r--    1 robertd  users        2446 Aug 14 13:32 prob.dmp.gz
>
> That's not what sort -k 5 is supposed to do.  It's supposed to sort
> lexicographically, so the proper order for the 1st four lines is:
>
> total 3165056
> -rw-r--r--    1 robertd  users        2446 Aug 14 13:32 prob.dmp.gz
> -rw-r--r--    1 robertd  users         678 Jul 10 15:15 
> rejected_tms_inbox.dmp.gz
> -rw-r--r--    1 robertd  users         840 Jul 21 13:50 161examples.dmp.gz
>
> because 2446 lexicographically precedes 678 (because "2" precendes "6").
>
> You probably want "sort -k 5n" or something like that.  However, it's still
> worrisome that "sort -k 5" doesn't work as it should.

Note that the whitespace before the number is part of the sort key:

   A field comprises a maximal sequence of non-separating characters and, in
   the absence of option -t, any preceding field separator.
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

So if you have right aligned numbers in a field, -n gives the same result
as without -n.

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
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]