Skip to content

Instantly share code, notes, and snippets.

@StryKaizer
Last active August 29, 2015 14:19
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 StryKaizer/e79e98aa7983b5fdaa7c to your computer and use it in GitHub Desktop.
Save StryKaizer/e79e98aa7983b5fdaa7c to your computer and use it in GitHub Desktop.
Find similar files in directory based on a file
#!/bin/sh
# Can be used to detect languages which lack translations in Commerce intl
# Usage:
# ./similar en.json - will compare all files in current dir with en.json
# ./similar en.json 5 - will compare all files in current dir with en.json
# and a threshold of under 5 lines being different before reporting
BASEFILE="$1"
LINE_DIFFERENCE_THRESHOLD=${2:-"40"}
for FILE in *.json
do
if [ "$BASEFILE" != "$FILE" ]
then
LINE_DIFFERENCE="$(diff -U 0 "$BASEFILE" "$FILE" | grep ^@ | wc -l)"
if [[ "$LINE_DIFFERENCE" -lt "$LINE_DIFFERENCE_THRESHOLD" ]]
then
FILE=${FILE%.json}
printf "'$FILE', "
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment