linux - 通讯命令不比较单词

标签 linux bash ubuntu comm

我正在尝试学习 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 不是这里的问题。你用过comm以错误的方式。 man comm状态

comm - compare two sorted files line by line



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

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

或者,如果您使用 bash (不是普通的 sh 或其他一些外壳)
comm <(sort file1.txt) <(sort file2.txt)

关于linux - 通讯命令不比较单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58725008/

相关文章:

bash - Unix:Bash:使用 head 命令后脚本会出现

node.js - Ionic 3 Cordova android 构建未显示在平台文件夹中,权限错误

linux - 无法在 Ubuntu : [[: not found 下安装 Genymotion 2.0.1

c++ - 绑定(bind)()错误 98 - "Address already in use"

linux - 使用while循环ssh到另一台机器

Bash 命令以冒号开头,在等号前有另一个冒号

bash - 将传感器输出提取到排序数组中

php - 使用 PHP 从 C 应用程序的 STDOUT 读取数据

linux - 查找和替换多个文件中的文本

macos - 如何将类路径永久添加到我的 Mac 终端?