This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: How to extract suffix from a filename?



This breaks on extensions that are not three characters, such as ".html".
(Note: This includes the period.) The following will work for any length
extension.

    ext=`basename $filepath | sed -e 's/\(.*\\.).*/\1/g'`

If you don't want the period:

    ext=`basename $filepath | sed -e 's/\(.*\)\..*/\1/g'`

________________________________
Glen Coakley, Sr. Software Engineer
MQSoftware Inc., (763) 543-4845


> -----Original Message-----
> From: Ehud Karni [mailto:ehud@unix.simonwiesel.co.il]
> Sent: Tuesday, June 26, 2001 7:01 AM
> To: malcolm.boekhoff
> Cc: cygwin@cygwin.com; Michael A. Chase
> Subject: Re: How to extract suffix from a filename?
> 
> 
> On Tue, 26 Jun 2001 10:38:17 +0100, malcolm.boekhoff 
> <malcolm.boekhoff@actfs.co.uk> wrote:
> >
> > Okay, it's a silly question - how can I extract the suffix 
> from a file
> > name (I know I can use "basename" and "dirname" to get the file and
> > directory components)?
> 
> if the suffix is of fixed length (usually 3 chars) then (in bash) the
> following will do: SUF=`echo <name> | tail -4c`
> 
> > I want to do this because my script executed from my 
> .mailcap file in
> > mutt spawns off internet explorer or word or whatever other 
> GUI thing is
> > required to read attachments like ".doc" and ".pps", etc.
> 
> Below are an example from my mailcap that does something like that and
> the bash scripts used.
> 
> Ehud.
> 
> 
> # my change to xv - to save in the original name
> image/*; ek-xv %s %{name}
> 
> # special case for SW fax files - *.SWD/*.swd
> application/octet-stream; ek-xv %s %{name} ;       \
>        test=swdchk.sh %{name} ;
> 
> 
> The 2 scripts used above (you might want to change the /bin/sh to
> /bin/bash, on my Linux and Cygwin /bin/sh=/bin/bash):
> 
> 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]