Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to replace text in all the files in one of my folders and am using Perl but getting an error.

This is what I am running:

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'm getting:

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

Can someone tell me what I should be doing? I've also tried several other methods but none seem to be working... I really need it to be done via command line so that it's faster because there are over ten million lines. Thanks!

like image 239
user1135462 Avatar asked Dec 09 '22 19:12

user1135462


2 Answers

The /es in your replacement text are being virewed as delimeters, and also as the division operator. You can either escape the slases as \/ where appropriate, or use alternate delimeters. Try:

perl -pi.bak -e 's#<START>#<url><loc>http://www.mysite.com/page/#g' *
like image 67
AlwaysBTryin Avatar answered Feb 20 '23 00:02

AlwaysBTryin


You need to escape slashes. s/<START>/<url><loc>http:\/\/www.mysite.com\/page\//g

like image 42
Ruu Avatar answered Feb 19 '23 23:02

Ruu