I want to get the filename (without extension) and the extension separately.
The best solution I found so far is:
NAME=`echo \"$FILE\" | cut -d\'.\'
You can force cut to display all fields and subsequent ones adding -
to field number.
NAME=`basename "$FILE"`
EXTENSION=`echo "$NAME" | cut -d'.' -f2-`
So if FILE is eth0.pcap.gz
, the EXTENSION will be pcap.gz
Using the same logic, you can also fetch the file name using '-' with cut as follows :
NAME=`basename "$FILE" | cut -d'.' -f-1`
This works even for filenames that do not have any extension.