I am using sort -r option to basically reverse the comparison in descending order. However, i found out that my file is not sorted according, can anyone please help.
My data is something like:-
Hello world
20.982342864 343
19.234355545 222
1.5567846 345
17.8767787 200
If I use the option -g or -n it works..but it is in ascending order. but I would like to display in descending order.I tried -nr but the Hello world line would be reverse as well as the last item.
My desired output would be
Hello world
20.982342864 343
19.234355545 222
17.8767787 200
1.5567846 345
What you need to do is tell "sort" that you want to sort numerically instead of alphabetically: "1,2,13,20" is sorted numerically, alphabetically sorted it would look like "1,13,2,20", because "1" comes before "2" in the "alphabet" (the ASCII code) the sort command uses. Aphabetical sorting is the default, numerical sorting can bei achieved by using the option "-n" as you have already found out. If you want to reverse the sorting you have to use "-r" as you have already noticed too. So combine these two to get: