Last active
November 27, 2022 15:11
-
-
Save isaaclw/0fe75d493fd11af632c31a95b073d26b to your computer and use it in GitHub Desktop.
wordle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
INCLUDE= | |
EXCLUDE= | |
COUNT= | |
while getopts ":i:e:m:ch" flag; do | |
case $flag in | |
i|include) INCLUDE="$OPTARG";; | |
e|exclude) EXCLUDE="$OPTARG";; | |
c|count) COUNT=1;; | |
m|map) MAP="$OPTARG";; | |
h|help) echo "usage: $(basename $0) [ options ] WORD_LIST_FILE | |
-i (include) comma list of characters | |
-e (exclude) bar list of characters | |
-c (count) instead of providing words, provide letter counts of non-excluded letters | |
-m (map) When certain characters are know, or known to not be, you can fill out a map like '[^a]b..c' | |
-h (help)"; | |
exit 0;; | |
:) error "option -$lastflag requires an argument";; | |
esac | |
lastflag="$flag" | |
shift $((OPTIND - 1)); OPTIND=1 | |
done | |
INCLUDE=$(echo "$INCLUDE" | sed 's/,/ /g') | |
EXCLUDE=$(echo "$EXCLUDE" | sed 's/,/|/g') | |
WORDLIST=~/.wordlist.txt | |
tmp1=$(mktemp) | |
tmp2=$(mktemp) | |
if [ -n "$EXCLUDE" ]; then | |
cat "$WORDLIST" | grep -vE "$EXCLUDE" | |
else | |
cat "$WORDLIST" | |
fi > "$tmp1" | |
for i in $INCLUDE; do | |
cat "$tmp1" | grep -E "$i" > "$tmp2" | |
mv "$tmp2" "$tmp1" | |
done | |
if [ -n "$COUNT" ]; then | |
for i in {a..z}; do | |
if echo "$INCLUDE" | grep -q "$i"; then # don't bother to check if it's already in the include list | |
continue | |
else | |
echo "$(cat $tmp1 | grep "$i" | wc -l) : $i" | |
fi | |
done | grep -vE "0 : " | sort -n | |
else | |
cat "$tmp1" | ( | |
if [ -n "$MAP" ]; then | |
grep -E "$MAP" | |
else | |
cat | |
fi | |
) | |
fi | |
rm -f "$tmp1" "$tmp2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment