Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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!

like image 646
dot Avatar asked Oct 23 '12 19:10

dot


1 Answers

Use another separator, like {}.

perl -pi -w -e 's{<body>}{...}g' /Volumes/Abc.html
like image 185
Birei Avatar answered Oct 04 '22 16:10

Birei