简体   繁体   English

使用终端在文本文件中查找和替换。 如何逃脱所有角色?

[英]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.

相关问题 在终端上设置 TOMCAT_HOME。 没有找到这样的文件或目录 - Setting TOMCAT_HOME on Terminal. No such file or directory found 重音字符出现在文本文件中,而不出现在终端(osx)中 - Accented characters appear in text file but not in terminal (osx) 以编程方式删除osx终端中2个字符之间的所有文本 - Programmatically delete all text between 2 characters in osx terminal 用bash / terminal上的其他字符串替换所有文件名中的字符串 - replace string in all file names with other string on bash/terminal 如何使用sed查找并替换为特殊字符? - How to find and replace with special characters using sed? 如何在MacOS中关闭终端的逃生通道? - How to close the escape of the terminal in MacOS? Terminfo:左箭头映射到默认OSX终端上的退格代码(8)。 为什么会这样呢? 以及如何改变呢? - Terminfo: left arrow is mapped to backspace code (8) on default OSX terminal. Why is it so? And how to change it? 在终端(macos)中使用转义字符打印文本 - Printing text with escape chars in terminal (macos) 如何将应用程序链接到usr / local / bin,以便可以在终端中全局调用它。 苹果电脑 - How do I link an application to usr/local/bin so I can call it globally in the terminal. Mac 如何在Mac终端中使用sed查找和替换字符串? - How to use sed to find and replace string in mac terminal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM