You can use a combination of `comm` and `uniq` to implement set intersection and union. https://ss64.com/bash/comm.html
> Return the unique lines in the file words.txt that don't exist in countries.txt
comm -23 <(sort words.txt | uniq) <(sort countries.txt | uniq)
>Return the lines that are in both words.txt and countries.txt: comm -12 <(sort words.txt | uniq) <(sort countries.txt | uniq)