我认为唯一的区别应该是稳定性。
所以我认为,如果第一个键是不同的,-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处理反斜杠时有什么规则吗?
我用一个更简单的例子修改了这个问题。
发布于 2017-09-20 03:36:19
$ 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|4https://stackoverflow.com/questions/46312527
复制相似问题