[mythtv-users] Bash Script help please
chris at cpr.homelinux.net
chris at cpr.homelinux.net
Wed Oct 11 00:11:42 UTC 2006
On Tue, Oct 10, 2006 at 06:02:33PM -0400, Jeff volckaert wrote:
> > TITLE=${TITLE//[^a-zA-Z0-9]/}
> What would the syntax be if I wanted to replace any non-alpha chars
> with an underscore?
TITLE=${TITLE//[^a-zA-Z0-9]/_}
or more simply
TITLE=${TITLE//[^[:alnum:]]/_}
This is likely to result in multiple consecutive underscores since
undesired characters are like to be surrounded by spaces. If you
want "Law & Order" to become "Law_Order" instead of "Law___Order"
then you want to try the following:
shopt -s extglob
TITLE=${TITLE//+([^[:alnum:]])/_}
The shopt command turns on extended regex parsing, and the +()
construct says to match the enclosed search pattern one OR MORE
times.
More information about the mythtv-users
mailing list