I want to replace the below string with new string in file test.cfg
.
There is only 1 occurrence of this string in the entire file.
Line in the test.cfg
file where this string is present:
global_filter = [ "a|^/dev/sdaa$|", "r/.*/" ]
String to be replaced is: '"a|^/dev/sdaa$|", "r/.*/"'
New string to be added is: '"a|^/dev/sdbb$|"'
I have the string to be replaced in $oldValue
variable and the new string in $newValue
variable.
After replacement inline, the line should look like
global_filter = [ "a|^/dev/sdaa$|", "a|^/dev/sdbb$|", "r/.*/" ].
I have tried all possible variants of sed
command, but could not succeed.
Please note that there are multiple spaces between square brackets which should be taken care of.
Kindly help me here.
sed
substitution escapes all metachars – steeldriver Feb 14 '17 at 12:55sed
(it will be nearly impossible to order by device name though if that's what your example is trying to suggest) but I think there are better tools for this job (that is, tools that read and edit INI files)