为什么在排序后选择唯一出现与仅选择唯一出现会产生不同的结果?
Why selecting unique occurrences after sorting holds different results than just selecting unique occurrences?
为什么
的输出
uniq | wc -l
不同于
sort | uniq | wc -l
哪一个真正拥有独特的事件?
它解释了 uniq
手册页中的行为,特别是:
By default, uniq prints its input lines, except that it discards all
but the first of adjacent repeated lines, so that no output lines are
repeated. Optionally, it can instead discard lines that are not
repeated, or all repeated lines.
The input need not be sorted, but repeated input lines are detected
only if they are adjacent. If you want to discard non-adjacent
duplicate lines, perhaps you want to use sort -u
. ( See sort invocation )
由于在输入 uniq
之前没有使用 sort
,因此无法准确计算唯一项的数量。
为什么
的输出uniq | wc -l
不同于
sort | uniq | wc -l
哪一个真正拥有独特的事件?
它解释了 uniq
手册页中的行为,特别是:
By default, uniq prints its input lines, except that it discards all but the first of adjacent repeated lines, so that no output lines are repeated. Optionally, it can instead discard lines that are not repeated, or all repeated lines.
The input need not be sorted, but repeated input lines are detected only if they are adjacent. If you want to discard non-adjacent duplicate lines, perhaps you want to use
sort -u
. ( See sort invocation )
由于在输入 uniq
之前没有使用 sort
,因此无法准确计算唯一项的数量。