I am trying to insert a line after each occurrence of a specific string in a text file. I tried with the lineinfile ansible module but it can only insert a line after the last or the first instance of the matched string in a file. Does anyone have any idea how I can achieve this using shell scripting or ansible playbook. I am using linux operating system so any unix command to solve this will help.
As shown below I am trying to insert mba after every line starting with foo:
Original txt file contents:
foo
ab
zz
foo='dummy'
cd
zz
foo='dats'
lm
xx
Required output:
foo
mba
ab
zz
foo='dummy'
mba
cd
zz
foo='dats'
mba
lm
xx