Date: Mon, 11 Jul 2005 21:34:37 +0200 From: =?ISO-8859-1?Q?Bj=F6rn_K=F6nig?= <bkoenig@cs.tu-berlin.de> To: Brian Henning <brian.henning@gmail.com> Cc: freebsd-questions@freebsd.org Subject: Re: OT: Shell script Message-ID: <42D2C9CD.9080009@cs.tu-berlin.de> In-Reply-To: <1f75ab0e050711113657ba7057@mail.gmail.com> References: <1f75ab0e050711113657ba7057@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Brian Henning wrote: > I am trying to write an SH script that i need some functionality. > > I want it to be able to get a filename without the extention on the end. > > for example. > > file.mp3 > > i would like it to return 'file'. > > Any ideas? This one looks ugly, but works fine: echo 'this.is.a.filename.with.extension' | awk -F. '{ i = 2; s = $1 } { while ( i < NF ) { s = s "." $i ;i += 1; } } { print s }' Don't hesitate to use awk. Although it looks more complex it's often "faster" than any equivalent solution with sed. Björn
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?42D2C9CD.9080009>