I would like to have a bash function that highlights a matched pattern upon a string.
Code:
cregex ()
{
local ptrn="$1"
local string="$2"
local -r rst="$( tput sgr0 )"
local -r blu="$( tput bold; tput setaf 39 )"
echo "$string" | sed -E 's/$ptrn/${blu}${ptrn}${rst}/'
}
But the function in not behaving as I would wish.
For instance
Code:
cregex "tput" "tput bold; tput setaf 39"
does not highlight the word "tput"