8.3.6 Union, Intersection and Difference of files

Combine sort, uniq and join to perform the equivalent of set operations on files:

Commandoutcome
sort -u file1 file2Union of unsorted files
sort file1 file2 | uniq -dIntersection of unsorted files
sort file1 file1 file2 | uniq -uDifference of unsorted files
sort file1 file2 | uniq -uSymmetric Difference of unsorted files
join -t '' -a1 -a2 file1 file2Union of sorted files
join -t '' file1 file2Intersection of sorted files
join -t '' -v2 file1 file2Difference of sorted files
join -t '' -v1 -v2 file1 file2Symmetric Difference of sorted files

All examples above operate on entire lines and not on specific fields: sort without -k and join -t '' both consider entire lines as the key.