sed ':0 N s/[0-9]// $!b0 : s/\(\w*\)\(\w\+\)\b\(.*\)\b\(\2\w*\)/\1\4\3/ s/\(\w\+\)\(.*\)\b\(\w*\1\)\b/\3\2/ t s/\(\(\w\).*\)\2/\1/ t /\w\n.*\w/c-1'