Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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
up vote 12 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 '14 at 11:04

Your Answer


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.