Finding anagrams

Inspired by the description in Jon Bentley's Programming Pearls, I implemented his elegant anagrammatization algorithm using only one (long) line of bash and the GNU core utilities:

for x in `cat /usr/share/dict/words`; do echo -ne $x '\t'; echo $x | tr [:upper:] [:lower:] | fold -w 1 | sort | tr -d '\n'; echo; done | sort -k2 | uniq -f1 --all-repeated=separate | cut -f1 | fmt -w 10000 | tr -s '\n'

The input file contains one word per line. The output will consists of 0 or more lines, each containing 2 or more words from the file. All the words in any one line will be anagrams of each other. All such anagrammatical sets will be enumerated.

But running this took (literally) hours, so I then wrote a similar thing in ugly, frangible C: anag.c. Rather than sorting the letters of each word, it fills a 26-item array with letter counts. Apart from that, the algorithm is identical.

Same thing in Common Lisp. This is turning into some kind of freakish obsession.