【问题标题】:comm command not comparing words通讯命令不比较单词
【发布时间】:2019-11-06 07:24:31
【问题描述】:

我正在尝试学习 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 ... 一切正常 任何帮助将不胜感激

【问题讨论】:

    标签: linux bash ubuntu comm


    【解决方案1】:

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

    comm - 逐行比较两个排序文件

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

    使用

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多