A(1,2,3) andB(3,4,5),A andB The intersection is3,A YesB The difference set is1 and2,B YesA The difference set is4 and5,A andB The result of the difference is1,2,4,5.

stayLinux Can be used incomm Command to find these sets.
[[email protected] tmp]# cat <<eof>set1.txt > orange > gold > apple > sliver > steel >
iron> eof [[email protected] tmp]# cat <<eof>set2.txt > orange > gold > cookiee >
carrot> eof
Usecomm command.
[[email protected] tmp]# comm set1.txt set2.txt apple orange comm: file 1 is not in
sorted order comm:file 2 is not in sorted order gold cookiee carrot silver
steel iron
Prompt is not sorted, thereforecomm It must be ensured that the comparison documents are in order.
[[email protected] tmp]# sort set1.txt -o set1.txt;sort set2.txt -o set2.txt
[[email protected] tmp]# comm set1.txt set2.txt apple carrot cookiee gold iron orange
silver steel

Output in the result3 column, Use tabs for each column\t Separate. The first column isset1.txt While there areset2.txt None of them. The second column isset2.txt While there areset1.txt None of them. The third column isset1.txt andset2.txt Both have.

According to these three columns, we can find the intersection, Sum of difference sets.

Intersection is the third column. Use-1 and-2 Deleting the first and second columns respectively is the result of the third column.
[[email protected] tmp]# comm set1.txt set2.txt -1 -2 gold orange
A YesB The difference set of is the first column,B YesA The difference set of is the second column.
[[email protected] tmp]# comm set1.txt set2.txt -2 -3 # A YesB Difference sets apple iron silver steel
[[email protected] tmp]# comm set1.txt set2.txt -1 -3 # B YesA Difference sets carrot cookiee
A andB The difference of is the combination of the first column and the second column.
[[email protected] tmp]# comm set1.txt set2.txt -3 apple carrot cookiee iron silver
steel
But it's not convenient to view the results in two columns, They should be processed so that they appear in the same column.
[[email protected] tmp]# comm set1.txt set2.txt -3 | tr "\t" "\0" apple carrot
cookiee iron silver steel