Results 1 to 4 of 4
Hello,
I would like to know what is the extension of a file
For example
filename="file.txt"
I'd like to put "txt" in a variable called ext
I see in an ...
- 08-21-2008 #1Just Joined!
- Join Date
- Aug 2008
- Posts
- 6
How to get file extension (without the dot) ?
Hello,
I would like to know what is the extension of a file
For example
filename="file.txt"
I'd like to put "txt" in a variable called ext
I see in an other post
http://www.linuxforums.org/forum/lin...xtensions.html
echo <filename> | grep -o '\.[^.]*$'
So I think I need to do something like
ext=`echo $filename | grep -o '\.[^.]*$'`
But I don't know how I should modify this to avoid the dot of ".txt"
and to get only "txt" in $ext.
Kind regards
- 08-21-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you are on bash
Code:# a=file.txt # echo ${a/*./} txt
- 08-21-2008 #3Just Joined!
- Join Date
- Aug 2008
- Posts
- 6
Thanks a lot
I also have post the same question at
How to get file extension (without the dot) - LinuxQuestions.org
with differents answers
- 08-22-2008 #4Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
This is Unix. There are many ways to get a thing done. That's why some love it and others hate it.


Reply With Quote
