mirror of
https://github.com/G2-Games/anagram-finder.git
synced 2025-04-19 11:12:53 -05:00
16 lines
426 B
Bash
Executable file
16 lines
426 B
Bash
Executable file
#!/bin/bash
|
|
word=$(echo $1 | xargs)
|
|
if [[ $word = "" ]]; then
|
|
echo "usage: ./anagram.sh <word>"
|
|
exit 1
|
|
fi
|
|
wordsorted=$(echo $word | grep -o . | sort | tr -d "\n")
|
|
lines=$(grep -xin -- "$wordsorted" sortedwords.txt | sed -e 's/:.*//g')
|
|
if [[ $lines = "" ]]; then
|
|
echo "No matches."
|
|
exit 0
|
|
fi
|
|
readarray -t lines <<<"$lines"
|
|
for i in "${lines[@]}"; do
|
|
sed "${i}q;d" words.txt | tr '[:upper:]' '[:lower:]'
|
|
done
|