Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 使用comm区分两个文件_Bash_Shell - Fatal编程技术网

Bash 使用comm区分两个文件

Bash 使用comm区分两个文件,bash,shell,Bash,Shell,我试图使用comm来计算两个排序文件之间的差异,但是结果没有意义,怎么了?我想显示test2中存在但不是test1的字符串,然后显示test1中存在但不是test2的字符串 >test1 a b d g >test2 e g k p >comm test1 test2 a b d e g g k p >测试1 A. B D G >测试2 E G K P >通信测试1测试2 A. B D E G G K P 在两个文件之间添加一个公共字符,在末尾说“z”。您

我试图使用comm来计算两个排序文件之间的差异,但是结果没有意义,怎么了?我想显示test2中存在但不是test1的字符串,然后显示test1中存在但不是test2的字符串

>test1 a b d g >test2 e g k p >comm test1 test2 a b d e g g k p >测试1 A. B D G >测试2 E G K P >通信测试1测试2 A. B D E G G K P
在两个文件之间添加一个公共字符,在末尾说“z”。您将看到出现第三列,以指示该值对两者都是通用的

输出旨在显示“col1中的数据是file1的uniq”,而“col2中的数据是file2的唯一数据”

最后,comm'-1、-2、-3'的参数表示从提供的列编号中抑制输出,例如,-1


我希望这会有所帮助。

要显示
test2
中存在但不在
test1
中的行,请编写以下任一行:

comm -13 test1 test2
comm -23 test2 test1
-1
隐藏只有第一个文件中有行的列;
-2
隐藏只有第二个文件中有行的列;
-3
隐藏两个文件中都有行的列。)

反之亦然,以显示存在于
test1
中但不存在于
test2
中的行

请注意,一行上的
g
被认为与后面有空格的
g
不同,这就是为什么

g
    g 
而不是

        g

@避难所:g是常用字符,无论如何,文件中必须有一些隐藏字符,这会破坏通信,我用相同的字母重写了文件,现在结果是正确的。@user121196:是的,很抱歉我错过了那个细节,我在读你的文章时没有戴眼镜。很高兴你找到了解决办法。祝你好运,找到那个尾随空间真是太好了。