Try something like this to start with. If you find problems, show us what you did to fix them. First. Before saying 'this does not work':
find /abc -type d |
while read dir
do
ls -1 /abc/$dir | awk -F '.' '{printf $(NF)' | sort -u |
while read suffix
do
printf "/abc/%s:*.%s" $dir $suffix
done
done
Comment: this appears to be an attempt to do something else, and this is a problem you hit on the way to that something else's solution. It is an unusual request.
Or:
Is this homework?
find /abc -type f -printf "%h %f\n" | awk '
{
EX = $2
sub ( /[^.]*[.]/, X, EX )
A[$1 FS EX]
}
END {
for ( k in A )
{
n = split ( k, T )
print T[1] "/:*." T[2]
}
}
'
#!/bin/bash
while read full_filename
do
directory="${full_filename%/*}/"
filenames="*.${full_filename##*.}"
echo "${directory}${filenames}"
done < <(find /abc -type f) | sort -u
I'm not saying it's pretty; it is just another alternative if that suits your coding style. It uses very few processes, which might be important to performance if you have lots of files.
Assuming that this is to be used by something else that will expand it all again, is there a reason not to build this process into that code and remove the need to juggle it all and then re-expand?