[英]Find and replace in text file with terminal. How to escape all the characters?
I'm trying to use the terminal to replace some html code in a file. 我正在尝试使用终端替换文件中的一些html代码。
This is the command I'm using 这是我正在使用的命令
perl -pi -w -e 's/find/replace/g;' /Volumes/Abc.html
I'm trying to replace 我正在尝试更换
<body>
with 同
<body>
<div style="text-align: center;page-break-after:always;padding-top:0%;">
<img src="images/image-001.jpg" id="illustration" alt="illustration" />
<div id="caption" style="text-align:right;font-style:italic;"></div>
</div>
so I've been trying this, but I can't figure out how to escape all the characters. 所以我一直在尝试这个,但我无法弄清楚如何逃避所有角色。 Can you help?
你能帮我吗?
perl -pi -w -e 's/<body>/<body>
<div style="text-align: center;page-break-after:always;padding-top:0%;">
<img src="images/image-001.jpg" id="illustration" alt="illustration" />
<div id="caption" style="text-align:right;font-style:italic;"></div>
</div>
/g;' /Volumes/Abc.html
Thanks! 谢谢!
使用其他分隔符,例如{}
。
perl -pi -w -e 's{<body>}{...}g' /Volumes/Abc.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.