Ubuntu – Overlapping/Comparing two files and printing what didn’t match

bashcommand line

Hello I have two files with some filenames that look like this:

File 1:

123.txt
456.txt
789.txt
101112.txt

File 2:

123.txt 
789.txt
101112.txt

Is there any bash command that I can use to overlapp them and to print only those lines or file names that didnt match. So I am expecting something like this:

456.txt

Best Answer

comm is your friend here:

If the files are sorted already:

comm -3 f1.txt f2.txt

If not sorted, sort and pass them as file descriptors using process substitution (so that we don't need any temporary files):

comm -3 <(sort f1.txt) <(sort f2.txt)

Example:

% cat f1.txt
123.txt
456.txt
789.txt
101112.txt

% cat f2.txt
123.txt
789.txt
101112.txt

% comm -3 <(sort f1.txt) <(sort f2.txt)
456.txt