• 0

Replace string within text files using Perl

Replace string within text files using Perl

replace-string-within-text-files-using-perl

To Replace string within text files using Perl all you have to do is:

perl -pi -e 's/oldstring/newstring/g' *

The search string has to be written in regular expression format so if you plan to replace for example a path with slashes such as "/my/path" to "/new/path"
you have to mask the special characters by using backslashes like this:

perl -pi -e 's//my/path//new/path/g' *

and that’s it.

Perl MAN Pages

Rating: 4.0/5. From 1 vote.
Please wait...
Jules

Jules

Jules is the owner and author of ISPIRE.ME. He's a Linux System Engineer, Tech fanatic and an Open Source fan.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.