与在bash多个小数的数字进行排序 [英] Sorting numbers with multiple decimals in bash
本文介绍了与在bash多个小数的数字进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在庆典
使用排序
与 -n
选择不给我预期的结果。
In bash
using sort
with the -n
option doesn't give me the expected result.
$ cat numbers | sort -n
1.0
1.1
1.11.4
1.15
1.3
1.3.3
1.4-p1
1.6.1
2.2.10
2.2.2
2.4
2.4.6
我试着用 -k1
, -k1.1n
等。( - k1.3n
只能得到启动与 1
)的数字正确的顺序。这似乎有一些非常基本的,我在这里失踪......
I tried using -k1
, -k1.1n
, etc. (-k1.3n
gets the order correct only for numbers starting with 1
). It seems there's something very basic I'm missing here...
推荐答案
您需要-t。标志来指定。作为您的分隔符,多个键位符处理逐渐变长/更深层次的数字。我还是不太明白究竟它是如何工作的,但它的工作原理...
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
或
cat numbers | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n
这篇关于与在bash多个小数的数字进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文