Unix shell replacing a word containing backtick in a file
Observe that this does not work:
$ sed "s/\<${actualtext}\>/${replacetext}/g" samplesqlfileFROM sampledatabase.`Datatype`
But this does:
$ sed "s/\<${actualtext}/${replacetext}/g" samplesqlfileFROM sampledatabase.`Datatype_details`
The problem was the \>
. The string variable $actualtext
does not end with a word-character. It ends with a quote. Consequently, \>
will never match there. The solution is to remove \>
.
To clarify, \>
matches at the boundary between a word character and a non-word character where the word character appears first. Word characters can be alphanumerics or underlines.
\>
is a GNU extension. The behavior under BSD/OSX sed will be different.
For purposes of illustration here, I removed the -i
option. For your intended use, of course, add it back.