What is the best solution to appending new text after an existing block of text in a text file, using a BASH script?
for example, I have a config file with the following:
[setting1]
...
[setting2]
...
[setting3]
I want to add some text after [setting2], e.g.:
test1=data
test2=data
test3=data
Therefore, I want it to look like this after the script is run:
[setting1]
...
[setting2]
test1=data
test2=data
test3=data
...
[setting3]
You could do this with
sed:(note new lines immediately after the
\characters).…or with the
-iflag to modify the file in-place: