Replace a certain string with string containing random rubbish

Hello,
in my shell script i have some multi-line text in a variable $TEMP - f.e.

blablahblah
blah blah
bla TARGET hgloglo

And i need to replace TARGET with text from another variable ($REPLACE), which is containing some text with nasty characters (\n, ", :, etc.) And stuff the altered text back into variable.

I've tried awk

TEMP=$(awk '{gsub(/TARGET/, "$REPLACE"); print}' <<< "$TEMP")

but "$REPLACE" is no longer a variable due its placement :frowning: and i assume that even if i managed to force this string to act as a varible, i would be scre*ed, because of tons of special characters deployed into gsub's second argument.

Any ideas? Try perl?

Thanks for even reading this horrid text - i'm sorry for my english.

TEMP=$(echo "${TEMP}" | awk '{gsub(/TARGET/, replace); print}' replace="$REPLACE")

Thanks a bilion, i've spent some time chewing through awk manual without sucess.

One thing. Dunno how it works on different machines but, i got to add "<<<", because it was using $TEMP as a filename.

TEMP=$(awk '{gsub(/TARGET/, replace); print}' replace="$REPLACE" <<< "$TEMP")

Thx thx