Comments Off on Set Operations in Linux
- Set Union
The set union operation unions two sets, i.e., join them into one set. We write C = A ∪ B to denote the union of sets A and B which produces set C.cat setA setB | sort -u
- Set common elements or intersection (C=A∩B)
sort setA > setA.sorted sort setB > setB.sorted comm -1 -2 setA.sorted setB.sorted
- Difference (subtraction) : C=A-B
The set A−B consists of elements that are in A but not in Bcomm -2 -3 setA.sorted setB.sorted
Similarly for The set B-A consists of elements that are in B but not in A
comm -1 -3 setA.sorted setB.sorted