我想按数字顺序对文件进行排序,并使用sort -nu [filename]
进行统一。
$ *** | sort -n | wc
201172
$ *** | sort -nu | wc
9599
$ *** | sort -un | wc
9599
$ *** | sort -n | sort -u | wc
201149
$ *** | sort -u | wc
201149
为什么sort -un
的行数会减少?所以我尝试在一个小数字文件上运行上面的命令,看看是否有任何问题。它按预期工作。
man sort
,没有提供有关此组合的信息。
提前致谢。修改
n
和u
选项?)答案 0 :(得分:2)
-u
删除重复项。
所以是的,显然如果在文件中重复密钥,它会减少行数。
与
的区别sort -n | sort -u
然后是第二个sort -u
管道命令考虑整行,而不仅仅是数字键。
答案 1 :(得分:0)
所以你需要了解-u和-n的含义是什么。
man sort
-u Unique: suppresses all but one in each set
of lines having equal keys. If used with the
-c option, checks that there are no lines
with duplicate keys in addition to checking
that the input file is sorted.
-n Restricts the sort key to an initial numeric string,
consisting of optional blank characters, optional
minus sign, and zero or more digits with an optional
radix character and thousands separators (as defined
in the current locale), which is sorted by arithmetic
value. An empty digit string is treated as zero.
Leading zeros and signs on zeros do not affect order-
ing.