Sorting numbers with multiple decimals in bash
You need the -t. flag to specify '.' as your separator, and the multiple key position specifiers handles the progressively longer/deeper numbers. I still don't quite understand exactly how it works, but it works ...
sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n numbers
or
cat numbers | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n
bash sorting numbers with decimals
With GNU sort:
sort -t "." -n -k1,1 -k2,2 file
Output:
1.1
1.2
1.10
3.2
Sorting decimals
You do not need to "${list[@]}"
but just $list
because it is just a string. Otherwise it gets all numbers in the same field.
$ for j in $list; do echo $j; done | sort -n
1
2
2.1
5
With your previous code it was not sorting at all:
$ list="77 1 2 5 2.1 99"
$ for j in "${list[@]}"; do echo "$j"; done | sort -n
77 1 2 5 2.1 99
Related Topics
How to Increase the /Proc/Pid/Cmdline 4096 Byte Limit
Dependency Walker Equivalent for Linux
How to Point a Docker Image to My .M2 Directory for Running Maven in Docker on a MAC
Makefile Command Substitution Problem
Receiving Udp Broadcast Packets on Linux
Can't Get Private Key with Openssl (No Start Line:Pem_Lib.C:703:Expecting: Any Private Key)
Why Do I Get "Suspended (Tty Output)" in One Terminal But Not in Others
Why Linux Kernel Use Trap Gate to Handle Divide_Error Exception
Difference Between Bash Pid and $$
What Character Sequence Should I Not Allow in a Filename
Building Arm Gnu Cross Compiler
Set Environment Variable with Space in Linux
Perf Stat Does Not Count Memory-Loads But Counts Memory-Stores
Is There Any Shortcut to Reference the Path of the First Argument in a Mv Command
Linker Error on Linux: "Undefined Reference To"
.Bashrc Not Read When Shell Script Is Invoked from Desktop Shortcut