Stuart Jansen wrote:
> FILE=$(echo $FILE | sed 's/....$//'
>
> Regular expressions are such useful things. KSH has some built in RE
> functions, that I think make it possible to do all this without forking.
> Bash might also.
Ooh, ooh! I just learned how to do this this week! Bash can indeed
manipulate strings like this when you're working with environment
variables. I don't think it's got full regexp support, but it's still
pretty powerful. If you want to chop the last four characters off the
value in VARNAME, then do this:
${VARNAME%%????}
or this:
${VARNAME::$((${#VARNAME}-4))}
If you want to do a replacement within the variable, then you can do:
${VARNAME/find/replace}
For example:
for FILE in *mp3; do
mv $FILE ${FILE%%mp3}ogg;
done
changes all the extensions of the .mp3 files in your directory to .ogg
(though it would probably be a good idea to re-encode them in the process).
Look up "Parameter Expansion" in the bash manpage.
Oh yeah, it would be pretty hard to do this just with cut, because there
isn't a way to specify "N characters from the end of the string." Use
sed or bash parameter expansion instead.
--
Soren Harward
[EMAIL PROTECTED]
_______________________________________________
newbies mailing list
[EMAIL PROTECTED]
http://phantom.byu.edu/cgi-bin/mailman/listinfo/newbies