extract file extension using sed

Hi,

how can i extract file extension using sed? for e.g., if a file name is abc.txt then how can i get "txt" (after .)

Thanks
praveen

echo  abc.txt  | sed 's/.*\.//'
txt

And awk one:

echo /home/abc.txt | awk -F"." '{print $NF}'

if using bash

# a=/home/abc.txt.pdf
# echo ${a##*.}
pdf

With zsh (also csh and tcsh):

% a=/home/abc.txt.pdf
% print $a:e
pdf

Hi, i have some task in which i have a parameter file say SQLREJ.dat and in the script i need to extract the file name only without extension i.e. SQLREJ. and i'm passing it while running the script as third parameter that is it is $3. till now i am extracting it's name by just typing $3 in the script. I sthere any other way so that i can only get file name without any extension? can anybody help me with this ASAP.
Thanks,
Manmeet

Manmeet, you should always start a new thread if you are asking a question about a new issue. It makes it clearer to everybody that this is a new request for help.

To answer your question, here are two ways of doing what you want in either bash or ksh

$ str=SQLREJ.dat
$ echo $str
SQLREJ.dat
$ echo ${str%\.dat}
SQLREJ
$ echo ${str%\.*}
SQLREJ

Thanks a ton...and i'll make it sure that next time i start a new thread for different request..