cerr cerr - 1 month ago 13
Linux Question

insert a line using sed

I have an ini file looking like:

...
abc = 123
def = 456
...


and I would like to change this to:

...
abc = 123
xyz = 987
def = 456
...


I've unsuccesfully tried this:
sed -i 's/abc = 123\ndef = 456/abc = 123\nxyz = 987\ndef = 456/g' myfile.ini

How do I fix my call to
sed
for this to work?

Answer

Another approach with sed:

sed '/abc = 123/N;s/\ndef = 456/\nxyz = 987&/' myfile.ini