3

The command watch -d produces a very interesting diff: it shows the most recent iteration of the command, and highlights (with inverse video) the differences to the previous iteration. This works specially well when lines are added or modified (deleted/moved lines cause spurious diffs to appear). I would like to use this kind of format to show fileB, with differences to fileA highlighted. This kind of comparisson does not seem to be available with the diff command.

Is it possible to reuse the implementation that watch uses, but not for running commands, but for generic files? I would like to do:

watch-diff fileA fileB 

So that I would see fileB, with changes (as compared to fileA) highlighted.

6
  • watch diff file1 file2 is not ok for you ? Commented Feb 19, 2015 at 11:56
  • Not really. I want the diff to be performed with the exact same algorithm that watch uses, and shown in the same way (with differences highlighted in reverse video). I have taken a look at the implementation in watch and seems to be very small and specific (not a library, as I initially thought). It is just a loop over all characters in the array, and straight 1 to 1 comparison of characters. Quite easy to implement in any language, but I would like to avoid reinventing the wheel. Commented Feb 19, 2015 at 12:05
  • 1
    vimdiff is also very useful in case you didn't know about it. Commented Feb 19, 2015 at 12:05
  • @don_crissti: sure, because probably your fileB is very different from fileA. Now, just change one character (with an editor, for example) and see what happens. Very useful when showing stuff which is properly tabulated and changes just a bit (for example, iptables reports) Commented Feb 20, 2015 at 9:29
  • @jeckyll2hide - allright, I see what you mean... I guess you could always write a script that does cat /path/to/fileA, watch the script and edit-in-place the path, e.g. { sleep 1; sed -i 's/fileA/fileB/' /path/to/myscript; } & watch -d myscript Commented Feb 20, 2015 at 11:57

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.