GNU bug report logs - #6700
Sort question

Previous Next

Package: coreutils;

Reported by: shtegtari <shtegtari <at> gmail.com>

Date: Thu, 22 Jul 2010 06:57:02 UTC

Severity: normal

Tags: moreinfo, notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Bob Proulx <bob <at> proulx.com>
To: shtegtari <shtegtari <at> gmail.com>
Cc: 6700 <at> debbugs.gnu.org
Subject: bug#6700: Sort question
Date: Thu, 22 Jul 2010 06:10:53 -0600
tags 6700 +moreinfo
thanks

shtegtari wrote:
> I have a text file that I can not sort correctly with the sort command, 
> no matter what switch I use.  I would send it but wanted to see first 
> whether anyone reads this email.
>
> Please respond and I will send the file.

Yes, people do read this mailing list.  You might get ten replies to
your posting.  But before sending a file the usual cause of confusion
is locales.  There is an FAQ entry for it.

  http://www.gnu.org/software/coreutils/faq/#Sort-does-not-sort-in-normal-order_0021

This is documented in the info page.

  info coreutils 'sort invocation'

     (1) If you use a non-POSIX locale (e.g., by setting `LC_ALL' to
  `en_US'), then `sort' may produce output that is sorted differently
  than you're accustomed to.  In that case, set the `LC_ALL' environment
  variable to `C'.  Note that setting only `LC_COLLATE' has two
  problems.  First, it is ineffective if `LC_ALL' is also set.  Second,
  it has undefined behavior if `LC_CTYPE' (or `LANG', if `LC_CTYPE' is
  unset) is set to an incompatible value.  For example, you get
  undefined behavior if `LC_CTYPE' is `ja_JP.PCK' but `LC_COLLATE' is
  `en_US.UTF-8'.

And the man page.

       *** WARNING *** The locale specified by the environment affects
       sort order.  Set LC_ALL=C to get the traditional sort order
       that uses native byte values.

What is your locale setting?

  $ locale

Does setting LC_ALL=C resolve your problem?

Personally I have the following set in my ~/.bashrc file.

  export LANG=en_US.UTF-8
  export LC_COLLATE=C

If that does not resolve your problem please try to reduce the test
case to the smallest possible amount that illustrates the problem.
Frequently this can be done on the command line with printf.

  $ printf "abc\nA B C\n" | sort
  A B C
  abc

Bob




This bug report was last modified 14 years and 364 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.