Using command line to replace text in all files in a folder?

I need to replace the text in all files in one of my folders, and I use Perl, but I get an error.

This is what I run:

perl -pi.bak -e 's/<START>/<url><loc>http://www.mysite.com/page//g' * 

Basically, I just need to replace

 <START> 

with this:

 <url><loc>http://www.mysite.com/page/ 

And this is the error I get:

 Illegal division by zero at -e line 1, <> line 1. 

Can someone tell me what should i do? I also tried several other methods, but nobody seems to work ... I really need this to be done through the command line, so that it is faster because there are more than ten million lines. Thanks!

+4
source share
2 answers

You need to avoid the slash. s/<START>/<url><loc>http:\/\/www.mysite.com\/page\//g

+4
source

In your replacement text, tags are designated as delimiters, as well as a separation operator. You can either exit slases as \ / where necessary, or use alternative delimiters. Try:

 perl -pi.bak -e 's#<START>#<url><loc>http://www.mysite.com/page/#g' * 
+10
source

Source: https://habr.com/ru/post/1443549/


All Articles