Identify how similar a file is to each file in a group of others.
#!/bin/bash | |
fileA="$1" | |
shift | |
for fileB in "$@"; do | |
( | |
# diff once grep twice with the help of tee and stderr | |
diff $fileA $fileB | \ | |
tee >(grep -cE '^< ' >&2) | \ | |
grep -cE '^> ' >&2 | |
# recapture stderr | |
) 2>&1 | ( | |
read -d '' diffA diffB; | |
printf "The files %s and %s have %s:%s diffs out of %s:%s lines.\n" \ | |
$fileA $fileB $diffA $diffB $(wc -l < $fileA) $(wc -l < $fileB) | |
) | |
done | column -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.