* nix中:执行列表的并集/交集/差 [英] *nix: perform set union/intersection/difference of lists
本文介绍了* nix中:执行列表的并集/交集/差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有时需要比较两个文本文件。显然,差异
显示的差异,它也隐藏的相似性,这是一种点的。
假设我想对这些文件的其他比较:并集,交集和减法,把每行作为集的元素
是否有同样简单的常用工具或单行能做到这一点?
例如:
A.TXT
约翰
玛丽
b.txt
ADAM
约翰
$> set_union A.TXT b.txt
约翰
玛丽
亚当
$> set_intersection A.TXT b.txt
约翰
$> set_difference A.TXT b.txt
玛丽
解决方案
联盟:排序-u
的文件... 的
交叉路口:排序
的文件... 的 | uniq的-d
区别:排序
的文件... 的 | uniq的-u
I sometimes need to compare two text files. Obviously, diff
shows the differences, it also hides the similarities, which is kind of the point.
Suppose I want to do other comparisons on these files: set union, intersection, and subtraction, treating each line as an element in the set.
Are there similarly simple common utilities or one-liners which can do this?
Examples:
a.txt
john
mary
b.txt
adam
john
$> set_union a.txt b.txt
john
mary
adam
$> set_intersection a.txt b.txt
john
$> set_difference a.txt b.txt
mary
解决方案
Union: sort -u
files...
Intersection: sort
files... | uniq -d
Difference: sort
files... | uniq -u
这篇关于* nix中:执行列表的并集/交集/差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文