Skip to content

Instantly share code, notes, and snippets.

@kevinthecity
Created May 26, 2023 19:43
Show Gist options
  • Save kevinthecity/e131a6df7a424163980fa649c8d7f4ca to your computer and use it in GitHub Desktop.
Save kevinthecity/e131a6df7a424163980fa649c8d7f4ca to your computer and use it in GitHub Desktop.
Script for finding keys in a folder directory
#!/bin/bash
# brew install the_silver_searcher https://github.com/ggreer/the_silver_searcher
# Add this script somewhere, and update permissions: chmod +x find_unused_keys.sh
# usage: ./find_unused_keys.sh keys.csv [optional: /path/to/search/]
# column 1 should be the key, column 2 should be the team name
CSV_FILE=$1
DIRECTORY=${2:-.} # Defaults to current directory if not provided
# Check if the CSV file and directory exist
if [ ! -f "$CSV_FILE" ]; then
echo "CSV file $CSV_FILE does not exist."
exit 1
fi
if [ ! -d "$DIRECTORY" ]; then
echo "Directory $DIRECTORY does not exist."
exit 1
fi
# Skip the first line (header) and then read the first word (up to the first comma) from each line
tail -n +2 "$CSV_FILE" | while IFS=',' read -r word rest_of_line
do
# Use ag to search the directory for the word
# If the word is not found, print it
if ! ag -l --silent "$word" "$DIRECTORY"; then
echo "$word"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment