I found a related question here:
How can I find all of the distinct file extensions in a folder hierarchy?
But my case is slightly different. Using bash on Ubuntu 14.04 Linux, if I have a bunch of files like the ones below:
ls -1 | sort -V
fileA.foo.bar.txt.gz
fileA.foo.foo.txt.gz
fileA.xyz.bar.txt.gz
fileB.foo.bar.txt.gz
fileB.foo.foo.txt.gz
fileB.xyz.bar.txt.gz
I would like to know how many files of each extension I get from the first separator found (e.g. \.
in the example). So it would be:
2 .foo.bar.txt.gz
2 .foo.foo.txt.gz
2 .xyz.bar.txt.gz
This is instead of the best answers that I found in the question above:
find . -type f | sed -e 's/.*\.//' | sed -e 's/.*\///' | sort | uniq -c | sort -rn
6 gz
find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort | uniq -c
6 gz