未检测到 UNIQ 命令重复的行



我在使用 unix uniq 命令时遇到了困难。我有一个包含如下所示的 id 列表的文件(head -5 list.txt 的输出(:

IBNUKWG02JZU4E
IBNUKWG02JZULO
IBNUKWG02JZUMG
IBNUKWG02JZUZS
IBNUKWG02JZV0R

该文件包含619142行(cat list.txt | wc -l(,并且包含重复项,例如,如果我运行命令(-c标志返回该行的出现次数(

cat list.txt | grep IBNUKWG02JZULO | uniq -c 

它返回

  2 IBNUKWG02JZULO

但是如果我运行命令(-u标志只打印唯一的行(

   cat list.txt | uniq -u | wc -l 

它返回619142,就像没有检测到重复的行一样。怎么可能?

在使用 Uniq 之前使用 sort。

cat list.txt | sort | uniq -u | wc -l 

最新更新