Hi guys,
I have been making a simple script for looking for anagram solutions in a word list (a file of 22k or so words).
At the moment it funtions like so:
User enters an 8 character string (whatever letters you want to find anagrams of, or solve rather)
The script moves all the words from the list that contain the first character to a temp file, then filters this to another temp file for those containing the 2nd character as well and so on until the only words left contain all 8 characters.
The problem i've hit is that there are, of course words left at the end that contain all 8 characters but also contain others and are not filtered out.
I'm sure there is a simple way of removing these and it may just be because i'm tired but it's not going anywhere at the moment!
My other thought was: Is there an option for grep that tells it to looks for the string in any order. i.e. you grep for the string 'Man' and it will give you back lines that match 'Man, nam, nma, anm mna' (if they were real words of course). This would obviously make the code rather simple and is possibly a bit hopeful..
Anyway, here's the code so far, I'm trying to avoid sed for the time being out of habit. I'm looking for a bit of advice rather then a complete solution.
function Start(){
echo Enter 8 Letter String.
read letters
for a in $(seq 1 8)
do
array[$a]=$(echo $letters | cut -c$a)
done
}
function FilterList(){
for b in $(seq 1 8)
do
c=$(($b+1))
grep ${array[$b]} TempList$b > TempList$c
rm TempList$b
done
cat TempList9
}
cat WordList > TempList1
Start
FilterList
Thanks for any advice offered.
edit: n.b This is not a pressing matter, just a small exercise I set myself to try and refresh my memory of shell scripting, so I am open to discussion of various other approaches you might use.