I am trying to do a find and replace with sed and BASH variables. As the replaced content contains many / characters, I have used # instead of /, as is typically used in sed:
sed -i "0,\#^$word#s##$replacement#" ./file
The item I want to replace contains the \ symbol:
replacement=$(echo "\macro{30\percent of bears eat fish.}")
However, when I do the replacement, \ always disappears.
- I do not have control over the content within
"\macro{30\percent of bears eat fish.}" - If
\tappears, it is interpreted as an indent, but I just want it to print as\tin the output.
How can I do a find and replace with sed when \, /, or other symbols might be found within the replacement text?
Note that you will still have problems with other characters, & and # in replacement string and of course all valid regex characters in the word string
The below takes care of the regular expression chars