gpt4 book ai didi

linux - 通讯命令不比较单词

转载 作者:行者123 更新时间:2023-12-04 18:57:08 25 4
gpt4 key购买 nike

我正在尝试学习 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com