[Techtalk] Question: sed s option in a shell script
Sabine Konhaeuser
sjmk at gmx.net
Tue Mar 15 04:13:06 EST 2005
On Monday 14 March 2005 02:56, Conor Daly wrote:
> On Mon, Mar 14, 2005 at 09:03:20AM +0100 or thereabouts, Almut
Behrens wrote:
> > On Sun, Mar 13, 2005 at 08:41:30PM -0800, Sabine Konhaeuser wrote:
> > > OLDSUFFIX=wav
> > > NEWSUFFIX=mp3
> > > for FILE in *."$OLDSUFFIX"
> > > do
> > > NEWNAME=´"$FILE" | sed -e "s/$OLDSUFFIX/$NEWSUFFIX/"´
> > > lame --preset standard "$FILE" "$NEWNAME"
> > > done
> >
> > You're close to the solution...
>
> And then, once you've got the solution (so you know sed works),
> there's always more than one way to do it... I'd use 'basename'
> here instead. basename has syntax like:
>
> basename "path/to/file.extension" [extension]
>
> and returns "file.extension" or "file." if you include the
> 'extension' bit. So: your filename.wav can be converted to
> filename.mp3 with:
>
> NEWNAME=`basename $FILE $OLDSUFFIX`mp3
>
> This does: "Take the filename of $FILE apart from the trailing
> $OLDSUFFIX bit and append the string 'mp3' to it"
>
> If you have directories included as part of the filename, you'd
> need to use 'dirname' to extract the path as well.
>
> NEWNAME=`dirname $FILE'`basename $FILE $OLDSUFFIX`mp3
>
> Conor
Thanks for all the tips. I'll give that a try tonight, when I'm back
on my home PC and will post the results.
Cheers,
Sabine
More information about the Techtalk
mailing list