help-gnu-utils
[Top][All Lists]
Advanced

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

Re: sort - specifying sort fields/keys.


From: Bob Proulx
Subject: Re: sort - specifying sort fields/keys.
Date: Tue, 8 Apr 2008 09:22:27 -0600
User-agent: Mutt/1.5.13 (2006-08-11)

cga2000 wrote:
> I wanted to sort the output of the ls command by filename and with 
> directories first and regular files last.
> 
> What I came up with does not quite behave as I expected:
> 
> $ ls -al --color=never | sort -k1.1,1.1r -k8f 

You shouldn't ever need --color=never there unless you have aliased ls
with ls --color=always.  You don't want ls --color=always (really you
don't) and therefore you won't need to undo it with --color=never.

> Why does .efile appear together with my other two [Ee]file's rather than
> just below .clewn_keys?
> 
> Looks like sort is ignoring the dots .. ??

You probably have set a locale setting that ignores punctuation.

> Side-effect of the "f" flag specified with my second sort key ..?

No.

> Something to do with my locale (en_US)?

Yes.  If a locale is set then the collation sequence for the locale is
used.  This is controlled outside of sort (and also ls and bash and
anything else that produces sorted output) and must be respected if
set.

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

Apparently the people who defined the collating sequence for the en_*
locales confused working with data on a computer with working with
text on a computer.  The locale collating sequences for en_* ignores
punctuation and folds case by default!

I have set the following in my environment to restore a standard sort
ordering:

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

Bob




reply via email to

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