Super User is a question and answer site for computer enthusiasts and power users. 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

How do I get a combined effect of diff -r left_dir right_dir and diff <(cat left_file | myfilter) <(cat right_file | myfilter) without much scripting?

share|improve this question

If your file names are simple (no whitespace etc.), you can use

find $left_dir -type f | while read left ; do
    diff <(myfilter $left) <(myfilter $right_dir$relpath)

If this is already "much scripting" and there are still problems (whitespace in file names, non-existing files on one side, etc.), you are probably out of luck.

share|improve this answer
Should be easy to work with whitespace if you quote the variables properly, and find … -print0 | while IFS= read -r -d '' … – slhck Jul 29 '13 at 9:41
@slhck: Sure. I just took that as "too much scripting" ;-) – choroba Jul 29 '13 at 9:43
this implements a single level of recursion. to get it right one would need to do find left -type d, find right_dir -type d, dump left and right difference and apply your code to intersection. – bobah Jul 29 '13 at 11:52
@bobah: What do you mean? If $left_dir/path/deeper/than/one exists, relpath will be path/deeper/than/one and the diff will compare the file with $right_dir/path/deeper/than/one. – choroba Jul 29 '13 at 12:09
@choroba: you are right, my comment was misleading. the above code won't report empty directories and files present in right but missing in left (though modification to make it working is rather simple) – bobah Jul 29 '13 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .