Created
February 8, 2019 07:47
-
-
Save RichardBronosky/45649cbb5ad3bc689e9523a3a59a1d7d 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 |
Author
RichardBronosky
commented
Feb 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment