I am needing to search and replace a string in a file with another string. Normally that can be done using
sed -i 's/old-text/new-text/g' input.txt
however that will not work if the replacement strings are options for commands like
INCPATH = -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I.
I have these strings stored in bash variables
new_string=$(sed -n '/INCPATH = /,/^$/p' Makefile_qmake)
old_string=$(sed -n '/INCPATH = /,/^$/p' Makefile_skeleton)
I need to perform the replacement, replacing the old_string with the new_string in the file.
sed -i "s/'${old_string}'/'${new_string}'/" Makefile
The problem is that sed
thinks that the replacement strings contain commands for itself. I do not want the commands in the replacement strings to be interpreted as commands. I want it to perform a blind search and replace, without expanding the commands.