bug-coreutils
[Top][All Lists]
Advanced

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

bug#6700: Sort question


From: Bob Proulx
Subject: bug#6700: Sort question
Date: Thu, 22 Jul 2010 06:10:53 -0600
User-agent: Mutt/1.5.18 (2008-05-17)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]