I try to insert a few lines of text before a specific line, but keep getting sed errors when I try to add a new line character. My command looks like this:
sed -r -i '/Line to insert after/ i Line one to insert \\ second new line to insert \\ third new line to insert' /etc/directory/somefile.txt
The error is reported:
sed: -e expression
I tried using \n , \\ (as in the example) no character at all, just moving the second line to the next line. I also tried something like:
sed -r -i -e '/Line to insert after/ i Line one to insert' -e 'second new line to insert' -e 'third new line to insert' /etc/directory/somefile.txt
EDIT !: Apologies, I wanted the text to be inserted before the existing one, and not after!
source share