How to insert multiple lines with sed

You're missing the trailing backslash at the end of some lines (and you have an eccessive newline at the end of the last line you want to insert):

sed -i '/the specific line/i \
#this\
##is my\
text' file
% cat file
foo
the specific line
bar

% sed -i '/the specific line/i \
#this\
##is my\
text' file

% cat file
foo
#this 
##is my 
text
the specific line
bar

With newlines:

% sed -i '/the specific line/i #this\n##is my\ntext' foo

% cat foo
#this
##is my
text
the specific line

Tags:

Bash

Sed