-
-
Save baditaflorin/33a93da648f0cbe19ebd1f50603d0866 to your computer and use it in GitHub Desktop.
Identify how similar a file is to each file in a group of others.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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