1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.