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=\n";

the code above is producing the following result:

echo "rpcallowip=

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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.