有两个名为compare 1.txt和compare2.txt的文件具有非顺序的随机数
cat compare1.txt
57
11
13
3
889
014
91
cat compare2.txt
003
889
13
14
57
12
90
瞄准
compare1中存在但不在Compare2中的所有数字的输出列表,反之亦然
如果任何数字的前缀中有零,则在比较时忽略零(基本上,数字的绝对值必须不同,才能视为不匹配) 示例-3应被视为与003匹配,014应被视为与14008匹配,与8等匹配
注-不必在同一行上进行匹配。 比较器1中第一行中的数字应视为匹配,即使比较器2中第一行以外的其他行中存在相同的数字
预期产量
90
91
12
11
PS(我不一定需要预期输出中的精确顺序,只要这4个数字以任何顺序都可以)
我试过什么
显然,我不希望第二个条件是正确的,我试着只满足第一个条件,但没有得到正确的结果。 我试过这些命令
grep -Fxv -f compare1.txt compare2.txt && grep -Fxv -f compare2.txt compare1.txt
cat compare1.txt compare2.txt | sort |uniq
编辑-Python解决方案也可以
给定这两个文件,在Python中,可以使用对称的集合差:
可进一步简化为:
有关Python集in the documents的详细信息
请您尝试以下,用GNU
awk
中显示的样本编写和测试解释:添加上述内容的详细解释
以下是如何使用awk实现您想要的功能:
但是这是
comm
存在的工作,你可以用它一次获得所有的差异和共同点。在以下输出中,col1仅为compare1.txt,col2仅为compare2.txt,col3在两个文件之间是通用的:或分别获得每个结果:
相关问题 更多 >
编程相关推荐