Separate file name and extension in script

Ibm Per processor d5 aix 5l v5.3
April 29, 2010 at 07:53:22
Specs: IBM AIX 5.3, 2GB RAM
Hi,

Given a file name as cimfil.dbd, I would like to separate the file name and extension into two different variables.

Please note that the file name and extension can contain any number of characters.

I would like to do this with native shell commands if possible, with out using awk or sed.

Can some one help?

Thanks,
Balaji.


See More: Separate file name and extension in script

Report •

#1
April 29, 2010 at 08:03:54
Hi All,

I found the answer.

file="thisfile.txt"

echo ${file#*.} ==> This displays "txt"

echo ${file%.*} ==> This displays "thisfile"

Thanks,
Balaji.


Report •

#2
April 29, 2010 at 08:21:51
You might find this link about basename and dirname interesting:

http://www.computing.net/answers/un...


Report •
Related Solutions


Ask Question