使用comm来区分两个文件 [英] using comm to diff two files
问题描述
我正在尝试使用comm来计算两个已排序文件之间的差异,但是结果没有意义,怎么了?我想显示在test2中但不在test1中的字符串,然后显示在test1中但不在test2中的字符串
I am trying to use comm to compute the difference between two sorted files, however the result doesn't make sense, what's wrong? I want to show the strings that exists in test2 but not test1, and then show the strings that exist in test1 but not test2
>test1
a
b
d
g
>test2
e
g
k
p
>comm test1 test2
a
b
d
e
g
g
k
p
推荐答案
要显示 test2
中存在的行,而不显示 test1
中存在的行,请编写以下任意一项:
To show the lines that exist in test2
but not in test1
, write either of these:
comm -13 test1 test2
comm -23 test2 test1
( -1
隐藏仅在第一个文件中存在的行的列; -2
隐藏仅在第二个文件中存在的行的列; -3
用两个文件中都存在的行隐藏该列.)
(-1
hides the column with lines that exist only in the first file; -2
hides the column with lines that exist only in the second file; -3
hides the column with lines that exist in both files.)
反之亦然,以显示存在于 test1
中但不存在于 test2
中的行.
And, vice versa to show the lines that exist in test1
but not in test2
.
请注意,一行上的 g
本身被认为与 g
不同,后跟一个空格,这就是为什么获得
Note that g
on a line by itself is considered distinct from g
with a space after it, which is why you get
g
g
代替
g
这篇关于使用comm来区分两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!