I am trying to edit a config file using a script that also performs other operations.
The script needs to find certain consecutive lines of text and remove these. In place it needs to paste a new configuration starting on the same line as where the old configuration was. In both the old and the new configuration, use of spaces matters.
in configfile.php, this block of text:
'session' =>
array (
'save' => 'files',
),
needs to be found and replaced with content I put in replacement.txt at the same location.
Based on answers to similar questions, one of the things I tried is this:
cat replacement.txt <(sed -i '1,/ 'session' => \n array (\n 'save' => 'files',\n ),/d' configfile.php) > configfile.php
This results in an empty file.
cat replacement.txt <(sed -i '1,/ 'session' => \n array (\n 'save' => 'files',\n ),/d' configfile.php) > newfile.php
This does the same as cat replacement.txt > newfile.php does and I want to edit a file, not create a new file.
Does anybody know what is wrong with my syntax and how I can fix it?
I've asked this question before here, but I didn't completely understand myself what I wanted, so it got a bit too elaborate and confusing. I use Debian Linux.
Edit based on comment:
The replacement.txt looks like this:
'session' =>
array (
'save' => 'redis',
'redis' =>
array (
'host' => '127.0.0.1',
'other_variable' => 'other_setting',
)
)
),
It is already indented the way it should be and can be inserted as is. Use of awk or sed is both fine.