I was desperate to use the sort command to sort a mixture of scientific and floating values that are both positive and negative, for example:
-2.0e+00 2.0e+01 2.0e+02 -3.0e-02 3.0e-03 3.0e-02
Without floating point or without scientific exponent, it works great with sort -k1 -g file.dat . Using both at once, as indicated above, this results in:
-3.0e-02 -2.0e+00 2.0e+01 2.0e+02 3.0e-02 3.0e-03
This is clearly wrong, as it should be:
-2.0e+00 -3.0e-02 3.0e-03 3.0e-02 ...
Any idea how I can solve this problem? And as soon as I solve this, is it possible to sort the absolute value (for example, get rid of the negative ones)? I know that I could try to square each value, sort, take the square root. By doing this, I would be less accurate, and it would be neat to have a nice, fast, and easy way.
My Linux system: 8.12, Copyright © 2011
Many thanks!
UPDATE: if I ran it in debug mode sort -k1 -g filename.dat --debug , I get the following result (I translated it into English, the output was German)
sort: the sorting rules for „de_DE.UTF-8" are used sort: key 1 is numerically and involves several fields -3.0e-02 __ ________ -2.0e+00 __ ________ 2.0e+01 _ _______ 2.0e+02 _ _______ 3.0e-02 _ _______ 3.0e-03 _ _______