I am using some sub(), gsub()
functions to replace content stored in a variable.
Say for example:
$ awk 'BEGIN {str="hello bee"; patt="llo"; gsub(patt,"XX",str); print str}'
heXX bee
This replaces in the string contained in str
all occurrences of llo
with XX
. Nice.
Now say that I want to use a more complex regular expression that uses both a variable and a pattern. For example, "he"
+ variable patt
. How can I do it?
If I try with gsub(/he/patt, ...)
it doesn't work:
awk 'BEGIN {str="hello bee"; patt="llo"; gsub(/he/patt,"XX",str); print str}'
Returns
hello bee
Instead of
XX bee