我想在特定行之前插入几行文本,但在尝试添加新行字符时仍然出现sed错误。我的命令看起来像:在使用sed的特定行之前插入多行文本
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
所报告的错误是:
sed: -e expression #1, char 77: unterminated `s' command
我尝试使用\n
,\\
(如上例),无字可言,只是移动第二行到下一行。我也试过类似的东西:
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
编辑!:道歉,我希望在现有的文本之前插入,而不是之后!
可能想,如果你使用了''插入后 – 123
是的,这是正确的。 – anubhava
绝佳的指南。非常感谢@anubhava –