delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/06/26/15:30:06

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <E1B42CFD544FD31193EE0000E87C5CE7E07EE1@mailserver2.mqsoftware.com>
From: Glen Coakley <gcoakley AT mqsoftware DOT com>
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)

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 
> <malcolm DOT boekhoff AT actfs DOT co DOT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019