comm 命令不比较单词

comm command not comparing words

我正在尝试学习 shell 编程,为此我在 windows 10 中使用 ubuntu 应用程序,我阅读了有关 comm 命令的信息,据我所知,它应该工作如下

file1.txt    file2.txt
abc          abc
cde          efg
a            b
b            c

the result should be
a
cde
             abc
             b
      c
      efg

but what I am getting is

abc
a
cde            
              b
       efg
       abc
       c

这就是我使用命令的方式

comm file1.txt file2.txt

我怀疑是因为我在 windows 应用程序上使用它,但其他命令(例如 grep uniq ps pwd ... 一切正常 任何帮助将不胜感激

Windows 不是这里的问题。您以错误的方式使用了 commman comm 个州

comm - compare two sorted files line by line

因此,您必须先对两个文件进行排序。

使用

sort file1.txt > file1sorted
sort file2.txt > file2sorted
comm file1sorted file2sorted

或者如果您使用的是 bash(不是普通 sh 或其他 shell)

comm <(sort file1.txt) <(sort file2.txt)