Skip to content

Instantly share code, notes, and snippets.

@daijo
Created January 23, 2013 09:08
Show Gist options
  • Select an option

  • Save daijo/4603451 to your computer and use it in GitHub Desktop.

Select an option

Save daijo/4603451 to your computer and use it in GitHub Desktop.
Prints all lines that only contains the given letters.
#!/bin/bash
# Prints all lines that only contains the given letters.
# Matching is case insensitive.
#
# usage: scrabble.sh FILE ABC
DICTIONARY_FILE=$1
CHARS_TO_USE=`echo $2 | tr '[a-z]' '[A-Z]'`
ALPHABET="ABCDEFGHIJKLMNOPQRSTUVXYZ"
FORBIDDEN_CHARS=`echo ${ALPHABET//[$CHARS_TO_USE]/}`
echo $CHARS_TO_USE
cat $DICTIONARY_FILE |
while read a; do
CANDIDATE_WORD=`echo $a | tr '[a-z]' '[A-Z]'`
valid=true
for (( i=0; i<${#FORBIDDEN_CHARS}; i++ )); do
char=${FORBIDDEN_CHARS:$i:1}
if [[ $CANDIDATE_WORD == *$char* ]]
then
valid=false
break
fi
done
if $valid
then
echo $CANDIDATE_WORD
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment