Re: extract chars after a last dot
From: Chris F.A. Johnson (c.f.a.johnson_at_rogers.com)
Date: 08/04/03
- Next message: Alan Murrell: "using MySQL's encrypt() function in a shell script"
- Previous message: Dan Mercer: "Re: ksh using getopt command"
- In reply to: mike: "extract chars after a last dot"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 4 Aug 2003 21:54:21 GMT
On Mon, 04 Aug 2003 at 11:22 GMT, mike wrote:
> hi
>
> i have files with names test.1 and test.file.10
> how do i extract the characters after the last dot? so in the example
> it would be
>
> 1) test.1 extract to "1"
> 2) test.file.10 extract to "10"
var=test.file.10
In a POSIX shell, such as sh (on *BSD), bash, ksh, etc.:
echo ${var##*.}
In any shell:
expr "x$var" : '.*\.\(.*\)'
--
Chris F.A. Johnson http://cfaj.freeshell.org
===================================================================
My code (if any) in this post is copyright 2003, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
- Next message: Alan Murrell: "using MySQL's encrypt() function in a shell script"
- Previous message: Dan Mercer: "Re: ksh using getopt command"
- In reply to: mike: "extract chars after a last dot"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|