How would I get Bash to match a regular expression, but rather than replace the value with a constant string, it will instead pass the matched value to a function, and then get the value to replace with from the return value of the function.
Something like the following pseudocode, which replaces every match of [a-d]
with the same character, but uppercase:
function uppercase() { echo ${1^^}; }
string="abcdefgh123cbazyz"
echo ${string//[a-d]/uppercase()}
# output: ABCDef123CBAzyz
I'm not particular, any language that is typically installed on a Unix system (such as sed
, awk
, or even the limited regex support built into bash
) can be used.