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

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like