我认为唯一的区别应该是稳定性。
所以我认为,如果第一个密钥不同,-k1
和-k1,1
应该相同。
但是,
$ cat test
A\ 1
A 4
A B 3
$ cat -A test
A\^I1$
A^I4$
A B^I3$
$ sort -t$'\t' -k1,1 test
A 4
A\ 1
A B 3
$ sort -t$'\t' -k1 test # tab is larger than backslash?
A\ 1
A 4
A B 3
$ sort --version
sort (GNU coreutils) 8.25
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and Paul Eggert.
sort
处理反斜杠时是否有任何规则?
我用更简单的例子修改了这个问题。
答案 0 :(得分:0)
$ cat testbar
A\|1
A|4
A B|3
$ sort -t'|' -k1,1 testbar
A|4
A\|1
A B|3
$ sort -t'|' -k1 testbar
A\|1
A B|3
A|4
如你所见,
-k1
选项让sort
首先按长度比较字符串。
如果您想让sort
直观地工作,请使用-d
选项。
$ sort -t$'\t' -k1 -d testbar
A B|3
A\|1
A|4