# sed new lines with \n as part of the line text

trying to write a new sed command that will insert new lines before another line.

the code i have tried and is failing is:

sudo sed -i '/# onlynet=ipv4/i echo "rpcallowip='$WebInternalIP'\n";\necho "rpcallowip='$DBInternalIP'\n";\necho "rpcallowip='$StratumInternalIP'\n";'$STORAGE_ROOT/yiimp/site/web/yaamp/modules/site/coin_form.php


The new lines need to read:

echo "rpcallowip=\$Variable\n"; example, echo "rpcallowip=127.0.0.1\n";


the code above is producing the following result:

echo "rpcallowip=10.0.0.3
";


So it is seeing the \n as another new line instead of part of the line.

## 1 Answer

As noted in the GNU Sed manual for the i\text command:

Escape sequences in text are processed, so you should use \ in text to print a single backslash.

Hence to insert the literal sequence \n, you will need to use \\n

• good grief the one thing I didnt try!!! thank you – jonathan adams Nov 4 '18 at 2:25