Skip to content

Instantly share code, notes, and snippets.

@baditaflorin
Forked from RichardBronosky/similarities.sh
Created September 17, 2019 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baditaflorin/33a93da648f0cbe19ebd1f50603d0866 to your computer and use it in GitHub Desktop.
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.
#!/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