Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Message-ID: From: Glen Coakley To: cygwin AT cygwin DOT com Subject: RE: How to extract suffix from a filename? Date: Tue, 26 Jun 2001 14:02:38 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-8" 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 AT unix DOT simonwiesel DOT co DOT il] > Sent: Tuesday, June 26, 2001 7:01 AM > To: malcolm.boekhoff > Cc: cygwin AT cygwin DOT com; Michael A. Chase > Subject: Re: How to extract suffix from a filename? > > > On Tue, 26 Jun 2001 10:38:17 +0100, malcolm.boekhoff > 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 | 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/