linux排序是否有不兼容的参数
我想按数字顺序对文件进行排序,并使用linux排序是否有不兼容的参数,linux,bash,sorting,Linux,Bash,Sorting,我想按数字顺序对文件进行排序,并使用sort-nu[filename]进行uniquify $ *** | sort -n | wc 201172 $ *** | sort -nu | wc 9599 $ *** | sort -un | wc 9599 $ *** | sort -n | sort -u | wc 201149 $ *** | sort -u | wc 201149 为什么使用排序-un的行数会减少?所以我试着在一个小的数字文件上运行上面的命令,看看是否有任何问题。它像
sort-nu[filename]
进行uniquify
$ *** | sort -n | wc
201172
$ *** | sort -nu | wc
9599
$ *** | sort -un | wc
9599
$ *** | sort -n | sort -u | wc
201149
$ *** | sort -u | wc
201149
为什么使用排序-un
的行数会减少?所以我试着在一个小的数字文件上运行上面的命令,看看是否有任何问题。它像预期的那样工作
- 我错过了什么明显的东西吗?或
- 那些选项彼此不兼容?我已经检查了
,没有提供有关此组合的信息。 提前谢谢man sort
- 我该如何解决这个问题?(分别使用
和n
选项?)u
-u
删除重复项
所以,是的,如果在文件中重复密钥,显然会减少行数
与
sort -n | sort -u
然后是第二个
sort-u
管道命令考虑整行,而不仅仅是数字键。因此您需要理解-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.
你怎么解释的?这读作“RTFM”。因此,它应该是一个注释。没有修复,您发出的命令已经很好了。您需要什么输出?再读一遍那个人。