can this regular expression be made possible to use for both filename.gz & filename.tar.gz
I want to get filename for both of these commands as just filename only:
echo "filename.tar.gz" | sed 's/\(.*\)\.\(.*\)\.\(.\)/\1/g'
echo "filename.gz" | sed 's/\(.*\)\.\(.*\)\.\(.\)/\1/g'
How do I strip the extension when the delimiter might occur multiple times in the filename?
For example:
I have 2 files as input for my script.
test.extension
test.foo.extension
In my script I want to see "test" and "test.foo" as results.
But the following script-snippet gives "test" for both files.
I know this is caused by the -f1 that I use as setting for cut. But I want to know which command I should use so it starts looking for the delim-character from the right i.s.o the left (probably a different command than cut, but which?)
!/bin/sh
FILE_NAME=$1
if [ ! -r ${FILE_NAME} ]
then
echo "Could not find file ${FILE_NAME}"
exit 1
fi
FNAME=`echo "${FILE_NAME}"| cut -f1 -d'.'`
echo "FNAME = ${FNAME}"