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.

don_crissti
  • 79,330
  • 30
  • 216
  • 245
user7290726
  • 69
  • 1
  • 10
  • Possibly related: [How to ensure that string interpolated into `sed` substitution escapes all metachars](http://unix.stackexchange.com/questions/129059/how-to-ensure-that-string-interpolated-into-sed-substitution-escapes-all-metac) – steeldriver Feb 14 '17 at 12:55
  • 1. This is the second time you're asking this question... 2. Yes, you can add new filters with `sed` (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) – don_crissti Feb 14 '17 at 13:01

0 Answers0