Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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).

share|improve this question

1 Answer 1

up vote 6 down vote accepted

This could be an approach:

diff <(nl file1) <(nl file2)

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

share|improve this answer
    
That's cool, I didn't know the nl program. Those unix tools are really handy, but there are so many of them. –  Fritz Jun 10 at 11:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.