How to insert text after a certain string in a file?
Right now I'm using
echo "Hello World" >> file.txtto append some text to a file but I also need to add text below a certain string let's say "[option]", is it possible with
Some text Random [option] Some stuff
Some text Random [option] *inserted text* Some stuff
You have to be more specific and give some sample text for people to help you with exact commands.
please edit you Q and show the `input` and the `output` lines. Because you Q is unclear. You could also do `echo "Hello World [option]" >> file.txt`, but it doesn't make sense.
I edited the question to provide more information for reference but the accepted answer was what I was trying to accomplish
Append line after match
sed '/\[option\]/a Hello World' input
Insert line before match
sed '/\[option\]/i Hello World' input
Additionally you can take backup and edit input file in-place using
-i.bkpoption to sed
on osx i get `sed: 1: "/pattern/a some text here": command a expects \ followed by text `