Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to impose a numeric sort on negative numbers?
- X-seq: zsh-users 24970
- From: Lawrence Velázquez <vq@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: How to impose a numeric sort on negative numbers?
- Date: Wed, 1 Jul 2020 14:48:02 -0400
- Cc: zsh-users@xxxxxxx
- In-reply-to: <CAKc7PVB7kJ_n7tvrC2Xog=XuhYxvE5iEUx9dnK5oOGBZijbTOg@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVB7kJ_n7tvrC2Xog=XuhYxvE5iEUx9dnK5oOGBZijbTOg@mail.gmail.com>
- Sender: zsh-users@xxxxxxx
> On Jul 1, 2020, at 1:45 PM, Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
>
> Hi,
> arr=( -1A -2b -3B 0 1A 2C 3B )
> print -rl ${(on)arr}
>
> Output:
> 0
> 1A
> -1A
> -2b
> 2C
> 3B
> -3B
>
> So it's not "correct". How to sort from -3 to 2?
arguably cheating, and not robust since no one has any idea how
clean your input is, but YOLO so whatever ;)
% arr=(-1A -2b -3B 0 1A 2C 3B)
% arr_sorted=(${(MOn)arr:#-*} ${(n)arr:#-*})
% print -rl $arr_sorted
-3B
-2b
-1A
0
1A
2C
3B
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author