A very simple way of doing what you are attempting is to sort
the output keeping only unique extensions, e.g.
find . -type f -regex ".*[.][a-zA-Z0-9][a-zA-Z0-9]*$" | \
awk -F '.' '{ print $NF }' | sort -u
if your sort
doesn't support the -u
option, then you can pipe the results of sort
to uniq
, e.g.
find . -type f -regex ".*[.][a-zA-Z0-9][a-zA-Z0-9]*$" | \
awk -F '.' '{ print $NF }' | sort | uniq
The -regex
option limits the find
selection to filenames with at least one ASCII character extension. However it will also pickup files without an extension if they contain a '.'
, e.g. foo.bar.fatcat
would result in fatcat
being included in the list.
You could adjust the regular expression to meet your needs. If your version of find
supports posix-extended regular expressions then you can prevent longer extensions from being picked up. For example to limit the extension to 1-3
characters, you could use:
find . -type f -regextype posix-extended -regex ".*[.][a-zA-Z0-9]{1,3}$" | \
awk -F '.' '{ print $NF }' | sort -u
There are other ways to approach this, but given your initial example, this is a close follow-on.