2

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.

  • watch diff file1 file2 is not ok for you ? – Darek Feb 19 '15 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. – dangonfast Feb 19 '15 at 12:05
  • vimdiff is also very useful in case you didn't know about it. – wurtel Feb 19 '15 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) – dangonfast Feb 20 '15 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 – don_crissti Feb 20 '15 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.