These two loops use diff -qr
to do an initial diff, principally
to get the filenames easily, then do an individual diff on the
found pair of files. sed
is used to clear the first N lines, or
to keep only the first N lines. First to clear N lines:
N=2
diff -qr dir1 dir2 |
grep '^Files.*differ' |
while read x a x b x
do diff --label "$a" --label "$b" -u <(sed "1,${N}s/.*//" <"$a") <(sed "1,${N}s/.*//" <"$b")
done
And this to keep N:
diff -qr dir1 dir2 |
grep '^Files.*differ' |
while read x a x b x
do diff --label "$a" --label "$b" -u <(sed -n "1,${N}p" <"$a") <(sed -n "1,${N}p" <"$b")
done
This assumes no spaces/tabs in filenames.
diff -r dir1 dir2
. You may also play with-I RE
option to ignore certain matching lines.