问题
I have a file like so:
1.1
3.2
1.2
1.10
I would like to sort the file so that it looks like so:
1.1
1.2
1.10
3.2
In other words, 1.10 is bigger than 1.2
I tried:
sort -nk 1,1 file
But I keep getting this, which is not what I want
1.1
1.10
1.2
3.2
Thanks
回答1:
With GNU sort:
sort -t "." -n -k1,1 -k2,2 file
Output:
1.1 1.2 1.10 3.2
回答2:
You may use the -V
option.
sort -V numbers
However this option is only in GNU Coreutils and could be absent from other implementation.
See https://stackoverflow.com/a/35386002/1107536
来源:https://stackoverflow.com/questions/46243957/bash-sorting-numbers-with-decimals