假设我们现在有两个文件 a.txt 、b.txt
a.txt 中的内容如下:
a c 1 3 d 4
b.txt 中的内容如下:
a b e 2 1 5
# Example 01
计算并集:
[[email protected]_81_181_centos ~]# sort -u a.txt b.txt 1 2 3 4 5 a b c d e [[email protected]_81_181_centos ~]#
# Exmaple 02
计算交集:
[[email protected]_81_181_centos ~]# grep -F -f a.txt b.txt | sort | uniq 1 a [[email protected]_81_181_centos ~]#
# Example 03
计算差集(a - b):
[[email protected]_81_181_centos ~]# grep -F -v -f b.txt a.txt | sort | uniq 3 4 c d [[email protected]_81_181_centos ~]#
# Example 04
计算差集(b - a):
[[email protected]_81_181_centos ~]# grep -F -v -f a.txt b.txt | sort | uniq 2 5 b e [[email protected]_81_181_centos ~]#
原文地址:https://www.cnblogs.com/leeyongbard/p/9667980.html
时间: 2024-10-25 02:42:49