Compare two files strictly line-by-line, without insertions or deletions

command linediff()file-comparison

I have two files that essentially contain a memory dumps in a hex format. At the moment I use diff to see if the files are different and where the differences are. However, this can be misleading when trying to determine the exact location (i.e. memory address) of the difference. Consider the following example showing the two files side-by-side.

file1:       file2:

0001    |    0001
ABCD    |    FFFF
1234    |    ABCD
FFFF    |    1234

Now diff -u will show one insertion and one deletion, although 3 lines (memory locations) have changed between the two files:

 0001
+FFFF
 ABCD
 1234
-FFFF

Is there an easy way to compare the two files such that each line is only compared with the same line (in terms of line numbering) in the other file? So in this example it should report that the last 3 lines have changed, along with the changed lines from file1 and file2. The output doen't have to be diff-style, but it would be cool if it could be colored (at the moment I color the diff -u output using sed so that could easily be adapted).

Best Answer

This could be an approach:

diff <(nl file1) <(nl file2)

With nl number the lines that diff recognizes the lines line by line.

Related Question