Having some trouble with sed outputting what I want:
I have my file contents (idmap):
idmap config ....
idmap config ....
File being written to (testing)
[global]
[global]
I used the following sed
command:-
sed '/\[global\]/ r idmap' /tmp/testing
The command works as expected and matches all [global]
tags and inserts the text after all occurrences of [global]
:
[global]
idmap config ....
idmap config ....
[global]
idmap config ....
idmap config ....
I try the following to match only the first occurrence of [global]
sed '0,\[global\]/ r idmap' /tmp/testing
Which then produces:
idmap config ....
idmap config ....
idmap config ....
idmap config ....
[global]
idmap config ....
idmap config ....
[global]
Any explanation of what is going on here would be most appreciated, awk
could also work for me, and how to get the desired output which would be:
[global]
idmap config ....
[global]
idmap config ....
Running on Centos 7.1 bash.