On Tue, 17 May 2005, Brock Noland wrote:

> I have a script which needs the extension of a file. The problem I am 
> having is how do I get the chars at the end of a filename after the LAST 
> period?
>
> For example:
>
> brock at brockwork backups $ ls -1
> another.tar.gz
> mydocs-backup-2005-05-17.tgz
> brock at brockwork backups $ ls | awk -F. '{ print $2}'
> tar
> tgz


You are taking what follows the the first period and preceeds the second 
one.  In awk "NF" means "number of fields" so "$NF" always means the last 
field.  So this will do it:

ls | awk -F. '{print $NF}'

As suggested, this does work, but it is longer and harder to remember:

ls | perl -p -e 's/^.*\.(.*)$/$1/'

It can be shortened to this (putting -p and -e together):

ls | perl -pe 's/^.*\.(.*)$/$1/'

Mike