user1135462
user1135462

Reputation: 175

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!

Upvotes: 4

Views: 839

Answers (2)

Ruu
Ruu

Reputation: 1245

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

Upvotes: 4

AlwaysBTryin
AlwaysBTryin

Reputation: 1964

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' *

Upvotes: 10

Related Questions