Bash. Get intersection from multiple files

Can you use

sort t1 t2 | uniq -d

This will combine the two files, sort them, and then display only the lines that appear more than once: that is, the ones that appear in both files.

This assumes that each file contains no duplicates within it, and that the inodes are the same in all the structures for a particular file.


You could try with comm utility

comm -12 <t1> <t2>

comm with appropriate combination of followinng optionns can be useful for different set operations on file contents.

   -1     suppress column 1 (lines unique to FILE1)

   -2     suppress column 2 (lines unique to FILE2)

   -3     suppress column 3 (lines that appear in both files)

This assumes <t1> and <t2> are sorted. If not, they should be first sorted with sort