Dowemo
0 0 0 0

This article introduces the ways to compute the intersection, union, and subtraction of two files under linux, providing complete test commands and demos.

Test file

A. Txt.

ac13d4

B. Txt.

ab
e215


Calculate union

sort -u a.txt b.txt

Output:

12345ab
c
d
e


Compute inte ection

grep -F -f a.txt b.txt | sort | uniq

Output:

1a


Calculate subtraction

A-b

grep -F-v-f b.txt a.txt | sort | uniq

Output:

3
4
c
d

B-a

grep -F-v-f a.txt b.txt | sort | uniq

Output:

2
5
b
e



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs