bug-coreutils
[Top][All Lists]
Advanced

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

Re: Bug in 'sort': negative numbers in non-first key


From: Andreas Schwab
Subject: Re: Bug in 'sort': negative numbers in non-first key
Date: Thu, 14 Sep 2006 11:33:58 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

Simon Anders <address@hidden> writes:

> However, when two keys are present, this fails to work:
>
>   $ sort -g
>   [IN ] 5 2
>   [IN ] 5 -3
>   [OUT] 5 2
>   [OUT] 5 -3

You are selecting the whole line as the sort key, and -g then instructs
sort to extract the leading numerical prefix from it.  Since the lines
compare equal on the sort key they are sorted lexicographically as the
last resort.  If you want to sort numerically on each field on the line
you have to specify each sort key separately, like sort -g -k1,1 -k2,2.

Andreas.

-- 
Andreas Schwab, SuSE Labs, address@hidden
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP 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]