I want to get the correct number of lines in the output of diff(specifically with -y and --suppress-common-lines options). Using a simple wc -l does not work, because if both files end without a newline and their last line is different wc -l won't count the last line.Is there a simple and efficient solution to avoid this?For example, if you have files a:abcd   #no newline hereAnd b:abcD    #no newline hereThe output is:$ diff -y --suppress-common-lines a b | wc -l0Which is obviously incorrect since diff does output a line.
Get correct number of lines in diff output
diff;wc
There is no newline, so wc -l is correct. Instead, you want to count the number of start of lines. One way to do it:$ diff -y --suppress-common-lines a b | grep '^' | wc -l1