Get correct number of lines in diff output

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 -l
1

It's not incorrect. A line has to be terminated by a LF character, otherwise, it's not a line (and anyway wc -l is documented to count newline characters, not lines).

You could pipe the output into something that adds back the missing LF character. GNU paste does it:

$ diff -y --suppress-common-lines <(printf a) <(printf b) | wc -l
0
$ diff -y --suppress-common-lines <(printf a) <(printf b) | paste | wc -l
1

It might not work with other implementations of paste, but since you're using GNU specific options to diff, we can probably safely assume that you have GNU paste as well. The behavior of text utilities for non-terminated lines is unspecified by POSIX.

Tags:

Diff

Wc