help-make
[Top][All Lists]
Advanced

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

Re: Sorting alphabetically


From: Philip Guenther
Subject: Re: Sorting alphabetically
Date: Thu, 17 Aug 2006 09:11:04 -0600

On 8/17/06, Maxim Yegorushkin <address@hidden> wrote:
Anoneironaut wrote:
> Hey guys.  I'm trying to sort a long list of files in alphabetical order.
> All of the files are case sensitive so I can't change the names at all.
> I've tried using the GNU sort function but it sorts things based on their

By "GNU sort function" you mean "the $(sort) function in GNU make", right?


> ASCII value and not alphabetically.  So for example with a list like this:
>
> A aa B bb
>
> I get:
>
> A B a b
>
> when I really want:
>
> A aa B bb
>
> Is it possible for me to do this?

Not using the built-in $(sort) function, as it always sorts using the
strcmp() ordering.


Huh?

$ echo -e "A\nB\naa\nbb\n" | sort

A
aa
B
bb

That's because you have LANG=en_US or something similar (LC_COLLATE?)
in your environment.  I know RedHat Linux has included that in their
default shell startup files for several versions.


To the original poster: if your platforms support the en_US collation
locale with the sort command than you can use that to obtain what you
want:

LIST = A B aa bb

# There's a single space between the single quotes in the 'tr' call
SORTED_LIST = $(shell echo ${LIST} | tr ' ' \\12 | LC_COLLATE=en_US sort)

all:
       @echo ${SORTED_LIST}


You may run into command line length limits if you're trying to sort
lots of file names, but if there are that many than do you really need
them sorted like this?


Philip Guenther




reply via email to

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