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

Re: How to impose a numeric sort on negative numbers?



> 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