Would like a generalized utility for creating regexp patterns on demand, based on command line parameter.
The following script is only intended to demonstrate the method of splitting and conversion. It is not the final product of how it will be used. NOTE: Yes, I did intend to use [[alphanum]] in sed, not [[alpha]].
My problem is that the output of the script (included below) for the command
scriptname abc
is
[Aa][BCbc]
when I want it to be
[Aa][Bb][Cc]
I am looking for the correct sed syntax directing the command repeating the substitution for each character individually, not only the first one.
Script:
#!/bin/bash
makePatternMatch()
{
echo "${charList}" | awk 'BEGIN{
regExp="" ;
}
{
if( $0 != "" ){
for( i=1 ; i <= NF ; i++ ){
regExp=sprintf("%s[%s%s]", regExp, toupper($i), tolower($i) ) ;
} ;
} ;
}END{
printf("%s\n", regExp ) ;
}'
}
explodeString()
{
charList=$(echo "${pattern}" | sed 's+[[alphanum]]*+&\ +g' )
}
for pattern in $@
do
explodeString
makePatternMatch
done