coreutils: Set operations

1 
1 8.3.6 Union, Intersection and Difference of files
1 -------------------------------------------------
1 
1 Combine ‘sort’, ‘uniq’ and ‘join’ to perform the equivalent of set
1 operations on files:
1 
1 Command                              outcome
1 --------------------------------------------------------------------------
1 ‘sort -u file1 file2’                Union of unsorted files
1                                      
1 ‘sort file1 file2 | uniq -d’         Intersection of unsorted files
1                                      
1 ‘sort file1 file1 file2 | uniq’      Difference of unsorted files
1                                      
1 ‘sort file1 file2 | uniq -u’         Symmetric Difference of unsorted
1                                      files
1                                      
1 ‘join -t'' -a1 -a2 file1 file2’      Union of sorted files
1                                      
1 ‘join -t'' file1 file2’              Intersection of sorted files
1                                      
1 ‘join -t'' -v2 file1 file2’          Difference of sorted files
1                                      
1 ‘join -t'' -v1 -v2 file1 file2’      Symmetric Difference of sorted
1                                      files
1                                      
1 
1    All examples above operate on entire lines and not on specific
1 fields: ‘sort’ without ‘-k’ and ‘join -t''’ both consider entire lines
1 as the key.
1