Linux sort doesn't work with negative float numbers

bash, linux, sorting, ubuntu, unix

Solution

All those troubles did my local settings. My ubuntu is in Czech:

$ echo $LANG
cs_CZ.UTF-8

In this local setting it's not a decimal point, rather a decimal comma that seperates integer from the rest (as we were thought in math classes, in our language we really do write comma instead of a point).

Therefore:

echo '0,03 >> 0,4 >
> -0,3 >
> 0' | sort -n
> 0
> -0,3 >
> 0,4 >
0,03 >

If you are writing a bash script, set the sorting routine to use the "normal" settings.

export LC_ALL=C

Problem

How to sort this kind of input? ``` 0.00159265291648695254 -0.00318530179313823899 0 0.00999983333416666468 0.00362937767285478371 0.00477794259012844049 -0.00637057126765263261 0.00681464007477014026 -0.00840724736714870645 -0.00522201549675090458 ``` Either `sort -n data` and `sort -g data` procudes this: ``` 0 0.00159265291648695254 -0.00318530179313823899 0.00362937767285478371 0.00477794259012844049 -0.00522201549675090458 -0.00637057126765263261 0.00681464007477014026 -0.00840724736714870645 0.00999983333416666468 ``` On the other hand `-1.whatever` would be in front of the zero. I need the sort to notice the minus signs. Thank you.

Original source