Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

left_dir=...
right_dir=...
find $left_dir -type f | while read left ; do
    relpath=${left#$left_dir}
    diff <(myfilter $left) <(myfilter $right_dir$relpath)
done

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

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.