uniq 将各行视为不同的行,但表面上它们是相同的

uniq 将各行视为不同的行,但表面上它们是相同的

我使用 vi 创建并编辑了一个名为 sort.txt 的文件,如下所示:

sentence one 
sentence two
sentence one
sentence three
sentence two
sentence two
sentence three
sentence one
sentence two
sentence one
sentence one
sentence one
sentence three
sentence four
sentence five

当我这样做时,sort sort.txt | uniq -c 我得到了这个:

  1 sentence five
  1 sentence four
  5 sentence one
  1 sentence one 
  3 sentence three
  4 sentence two

另外,当我写 时sort sort.txt | uniq -u,“句子一”也出现在那里。我不明白为什么“句子一”会出现两次,好像内容不同,有人能解释一下为什么吗?

答案1

第一个末尾有尾随空格sentence one

$ cat -et sort.txt
sentence one $
sentence two$
sentence one$
sentence three$
sentence two$
sentence two$
sentence three$
sentence one$
sentence two$
sentence one$
sentence one$
sentence one$
sentence three$
sentence four$
sentence five$

相关内容