我试图在" rezhome"之前添加一行。在文件中,如下所示:
...
app3-reservation, \
app4-reservation, \
app5-reservation, \
rezhome
当我使用以下命令在本地运行时,它可以正常工作。
sed -i 's/rezhome/app5-reservation, \\\n&/' grouphost.cfg
但是使用ssh反斜杠并没有转义,我得到了结果
ssh localhost "sed -i 's/rezhome/app5-reservation, \\\n&/' /path/grouphost.cfg"
...
app3-reservation, \
app4-reservation, \
app5-reservation, \nrezhome
请帮忙吗?
答案 0 :(得分:6)
\
和sed
同时处理ssh
,因此您需要进一步转义它们以便同时使用它们。尝试:
ssh localhost "sed -i 's/rezhome/app5-reservation, \\\\\n&/' /path/grouphost.cfg"