Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash - how to sort negative values? [duplicate]

Tags:

bash

sorting

is there a way to sort negative numbers with sort in bash ? I have sin written out

...
0.250109
0.188852
0.126850
0.064349
0.001593
-0.061168
-0.123689
-0.185722
-0.247023
-0.307349
...

and the problem is when I run sort on it, it just sorts it by values - regardless of the minus in front of some values. Is there a way to fix it ? Thanks

like image 519
Jesse_Pinkman Avatar asked May 12 '26 20:05

Jesse_Pinkman


1 Answers

Use sort -g (--general-numeric-sort), not sort -n (--numeric-sort).

See sort Invocation for an explanation of the subtle differences between these two options.

like image 123
Guido Avatar answered May 15 '26 09:05

Guido



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!