linux - linux下两个文件的交集

标签 linux unix centos

我需要比较lunix中两个文件之间的差异,我需要交集,例如我在第一个文件test.txt中的这行

aaaa 布布 CCCC dddd

在第二个文件 test2.txt 中这行

哎呀 噗噗 啊啊啊 咕咕 dddd

我需要这样的结果

aaaa dddd

我使用这个命令

comm -23 <(sort -i  /var/test.txt) <(sort -i  /var/test2.txt) > g.txt

这就是结果

bbbb cccc

我需要 test 和 test1 之间的交集任何帮助

grep 获取内存

最佳答案

人通讯:

 EXAMPLES
        comm -12 file1 file2
               Print only lines present in both file1 and file2.

所以:

$ comm -12 <(sort -i  test.txt) <(sort -i  test2.txt)
aaaa
dddd

关于linux - linux下两个文件的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47034924/

相关文章:

linux - 仅具有读取权限从 unix/linux 服务器复制文件的一小部分

bash - 查找端口号和域名以连接到 Hive 表

linux - 这个for循环出了什么问题?

linux - 当我使用路径压缩 tar gz 文件时,文件夹会被包含在内

linux - Apache 中的 .htaccess 不工作

xml - 搜索特定字符串后获取 xml 中元素值的 shell 脚本

linux - 如何使用字符串分隔符将 stderr 重定向到 stdout

linux - 使用 iptables 打开端口

node.js - Centos Node ,什么都没有发生

linux - CentOS/auditd : file creation at directory to trigger a script