bug-coreutils
[Top][All Lists]
Advanced

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

Re: sort bug


From: Bob Proulx
Subject: Re: sort bug
Date: Mon, 2 Apr 2007 22:33:02 -0600
User-agent: Mutt/1.5.9i

ara wrote:
> Please test the following
> 
> sort <<EOF
> 10 sfdafdsafdsa
> 1 safdfdsafsd
> 22
> EOF
> 
> the output is wrong
> 
> 10 sfdafdsafdsa
> 1 safdfdsafsd
> 22

Thank you for your bug report.  However your symptoms match a very
common signature that is not a bug in sort.  This would be the sort
order if you picked a a locale such as en_US.UTF-8.

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

Try setting your locale variable to C.

LC_ALL=C sort <<EOF
10 sfdafdsafdsa
1 safdfdsafsd
22
EOF
1 safdfdsafsd
10 sfdafdsafdsa
22

The info documentation says:

     (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'.

My personal configuration is:

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

Also with no options sort will lexically sort across the entire line.
If you have data that is a mix of number and text you probably want to
specify the fields to sort upon to sort with the -k option.

LC_ALL=C sort -k1,1n -k2,2 <<EOF
10 sfdafdsafdsa
1 safdfdsafsd
22
EOF
1 safdfdsafsd
10 sfdafdsafdsa
22

Bob




reply via email to

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