Hello Everyone,
In one of my script, I would like to sort the decimal numbers.
For e.g.
If I have numbers like
1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.10 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9
I would like to sort them
1.0 1.1 1.2 2.0 2.1 3.0 4.0 5.0 6.0 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 7.10
that means, 1.10 is greater that 1.2.
Can you please help me out to achieve this.
Kind Regards,
Sachin
Where are these numbers stored? If they appear line by line in a file, you can use sort command.
sort -nk1,1 filename
If you have the list of numbers in a variable (say LIST), you can use
echo $LIST | tr " " "\n" | sort -nk1,1
Please discard this solution. I read the problem as "sorting decimals" from the subject. The problem is slightly different here.
Subbeh
3
Try this:
sort -t. -k1,1n -k2,2n
If it's one line, you'll have to split it first:
tr ' ' '\n' < file
try..
cat filename| tr ' ' '\n' | sort -t. -nk1,1 -k2,2|tr '\n' ' '