#! /bin/bash
q=`echo -n
"$1" | sed -n 's/[a-zA-Z]/&\n/pg' | sort | sed ':a;N;s/\n//;$!ba'`
s=`echo -n
"$q" | sed "s/[a-zA-Z]/[$q]/g"`
echo $s
sed -n
"/^$s$/"'{=;p;s/./1&\n/pg;}' /usr/share/dict/linux.words |
sed -n
'N;s/\n/ /;h;s/.*//;:a;n;s/^$/2z/;x;p;x;p;tb;ba;:b' |
sed -n
'N;s/\n/ /p' |
sort -n |
sed -n
":a;N;s/\n[0-9]* [^ ]* 1\([^ ]*\)$/\1/;ta;s/^[0-9]* \([^ ]*\)
1$q\n.*/\1/p"