Home / Software / Find and replace text in multiple files

Find and replace text in multiple files

Perl dark
Question: How can I find and replace text in multiple files?

Answer: If you have perl installed on your server, you can easily use it to perform the function you need. Even if you do not have root access to the server, basic user SSH access will be enough.

Let’s start with a simple example. If you wanted to replace every instance of the word “captain” with the word “major” in all of your html files, you would enter the follow from the command line:

perl -pi -e "s/captain/major/g;" *.html

That is all it takes. Perl will search every html file in the current path and change all of the captains to majors. This is very useful if you need to edit multiple files at once and do not want to go through the trouble of opening, changing, and saving each one.

Photo: Flickr

Check Also

servers

Importance of web hosting to business

The world of business is very ruthless and unfair in some cases. It is a …

Powered by Namesco
© Copyright InternetBlog.Org.Uk 2024, All Rights Reserved