The file has the content:
[Greet] Hello Hi Hola
I want to add a string called
Hey so that its position is after
[Greet] Hello Hey Hi Hola
Is there a way to do the above by using
echo or other native linux tools from the command line?
sed command to insert or append lines requires a line break it is easiest to place the
sed command in a file and tell
sed to execute that file.
Example: to insert
Hey after (every)
Hello, create the following file:
sed -f appendheyafterhello.sed < sourcefile > resultfile
Here are more
sed commands including how to insert a line before a pattern or at a specific line number.
Here's some perl solutions:
perl -p -i -e 'print "Hey\n" if /Hi/' filename
perl -p -i -e 'print "Hey\n" if $. == 4' filename
perl -n -i -e 'print; print "Hey\n" if /Hello/' filename