wordmatch

#!/usr/bin/env sh
 
# Exit on error
set -e
 
# Check if at least 2 arguments (path and one word)
if [ $# -lt 2 ]; then
  echo "Usage: $0 <directory> <word1> [word2] ..."
  exit 1
fi
 
# Check if directory exists
if [ ! -d "$1" ]; then
  echo "Error: Directory $1 not found"
  exit 1
fi
 
# Get directory and shift to remove it from args
dir="$1"
shift
 
# Create pattern from remaining args
pattern=$(printf "%s\|" "$@" | sed 's/\\|$//')
 
find "${dir}" -name "*.md" -exec grep -l "${pattern}" {} +
#!/usr/bin/env sh
 
# Exit on error
set -e
 
# Check if both arguments are provided
if [ $# -ne 2 ]; then
  echo "Usage: $0 <directory> <stopwords-file>"
  exit 1
fi
 
# Check if directory exists
if [ ! -d "$1" ]; then
  echo "Error: Directory $1 not found"
  exit 1
fi
 
# Check if stopwords file exists
if [ ! -f "$2" ]; then
  echo "Error: Stopwords file $2 not found"
  exit 1
fi
 
find "${1}" -name "*.md" -exec cat {} + |
  tr '[:upper:]' '[:lower:]' |
  tr -cs '[:lower:]' '\n' |
  grep -v -w -f "$2" |
  sort |
  uniq -c |
  sort -rn