[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug in sort numeric mode with . separator
From: |
P |
Subject: |
Re: bug in sort numeric mode with . separator |
Date: |
Wed, 01 Dec 2004 19:35:03 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040124 |
Matthew M. Boedicker wrote:
Sorry, this isn't a bug. Should have read the FAQ. "export LC_ALL=POSIX"
fixed it.
Well really that's just relying on the fact that '.' is before [0-9]
in the C locale. The following is more explicit/robust and should
work for all locales:
echo -e "80.58.11.107\n80.58.1.111" | sort -k1,1n -k2,2n -k3,3n -k4,4n
-t'.'
`info sort` has loads of great examples explaining this
(very confusing) behaviour. The essential point I'm quoting
from the info docs is:
"""
sort -t : -k 2,2n
Note that if you had written `-k 2' instead of `-k 2,2' `sort'
would have used all characters beginning in the second field and
extending to the end of the line as the primary _numeric_ key.
For the large majority of applications, treating keys spanning
more than one field as numeric will not do what you expect.
"""
I guess it's only has that confusing behaviour (i.e. not
treating the field specifier specially) for backwards compatability?
--
Pádraig Brady - http://www.pixelbeat.org
--