diff command to get number of different lines only

Posted on Jan 18, 2023

Question

Can I use the diff command to find out how many lines do two files differ in?

I don't want the contextual difference, just the total number of lines that are different between two files. Best if the result is just a single integer.

Answer

diff can do all the first part of the job but no counting; wc -l does the rest:

diff -y --suppress-common-lines file1 file2 | wc -l