Linux sort doesn't work with negative float numbers
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
Bash - how to sort negative values?
my problem was that the data wasnt well formatted - because of my locale, I had to sed decimal point into decimal comma - that's how its written in czech republic
thanks
sort numeric column based on absolute values and scientific notation
sed 's/^-\(.*\)/\1-/' | sort -g | sed 's/^\(.*\)-$/-\1/'
The idea is to transform every negative number -123
into 123-
, then sort numerically (which ignores the trailing -
), then undo the transformation.
How to sort a file, based on its numerical values for a field?
Take a peek at the man page for sort...
-n, --numeric-sort
compare according to string numerical value
So here is an example...
sort -n filename
Related Topics
Perl Fork() Exec() , Child Process Gone Wild
How to Append to an Indirect Parameter Expansion of an Array in Bash
When We Run an Executable, Do All the Sections Get Loaded into Memory at Once
Process Stuck in Exit, Shows as Zombie But Cannot Be Reaped
Transport Endpoint Not Connected - Mesos Slave/Master
Why Does This Movq Instruction Work on Linux and Not Osx
How to Tell If Running in a Linux Console Versus an Ssh Session
How to Manage Log Verbosity Inside a Shell Script
/Usr/Bin/Ld: Client: Hidden Symbol '_Dso_Handle'
Error Marking Master: Timed Out Waiting for the Condition [Kubernetes]
Why Does If [ !$(Grep -Q) ] Not Work When If Grep -Q Does
Unterminated Address Regex While Using Sed
Does the Linux Scheduler Prefer to Run Child Process After Fork()
Nacl Helper Process Running Without a Sandbox Error Using Chrome Through Selenium in Linux
Can Any One Say How to Install the Slack in Ubuntu14.04 and While Trying This Was the Error