GNU bug report logs -
#6790
locale sort ordering confusion
Previous Next
Full log
Message #20 received at 6790 <at> debbugs.gnu.org (full text, mbox):
Hi George,
On Wed, Aug 04, 2010 at 01:32:55AM +0530, George Thomas Irimben (georgeti) wrote:
> I would like to report a problem(bug?) I am facing with sort command in
> Linux.
>
> Sorting of a simple text file using simple sort command is giving me
> incorrect result.
>
> Here is the problem:
>
> Text file to sort has 3 lines
> my-lnx7% cat y
> abc/d,ABC
> abc/,XYZ
> abc/o,MNO
>
> sort command from Linux is giving me below result(According to me, this
> result is incorrect)
>
> my-lnx7% sort y
> abc/d,ABC
> abc/o,MNO
> abc/,XYZ
>
> But, result expected is as below. Because "," is ahead of "d" in ASCII
> table.
> Same found working on Unix using same input file, same command line.
>
> abc/,XYZ
> abc/d,ABC
> abc/o,MNO
>
>
> Pls let me know if this is a problem in Linux or I am missing something.
You missed the effects of locale settings (see
http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#Sort-does-not-sort-in-normal-order_0021).
$ printf "abc/d,ABC\nabc/,XYZ\nabc/o,MNO\n" | LC_COLLATE=en_US.UTF-8 sort
abc/d,ABC
abc/o,MNO
abc/,XYZ
$ printf "abc/d,ABC\nabc/,XYZ\nabc/o,MNO\n" | LC_COLLATE=C sort
abc/,XYZ
abc/d,ABC
abc/o,MNO
Erik
--
If you're willing to restrict the flexibility of your approach,
you can almost always do something better.
-- John Carmack
This bug report was last modified 15 years and 9 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.