Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Feature request: two level sorting



On 16 June 2016 at 01:02, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> Well, this old trick always works if you don't mind depending on /
> being readable, but that's probably a safe assumption usually.
>
> % myarray=("aaa-A" "aab-B" "aac-A" "aad-C")
> % echo /(e:'reply=($myarray)':oe:'REPLY=${REPLY#*-}':)
> aac-A aaa-A aab-B aad-C


Could this be used to alter numeric sort a little? The point is to
have numbers be ordered *after* letters, not *before* letters. Example

# a=( "aaa" "aeg" "aa1" "ae2" )
# echo ${(on)a[@]}
aa1 aaa ae2 aeg

This places "1" before "a" (1 < a) and "2" before "g" (2 < g). With
this reversed, the result would be:

aaa aa1 aeg ae2

So now a < 1 and g < 2.

Best regards,
Sebastian Gniazdowski



Messages sorted by: Reverse Date, Date, Thread, Author