Replace content of multiple files

Problem

Imagine you have some misspelled words in some documents:

$ grep Intalac *
file02.html: <h2 align="left"><a name="ubuntu"></a>Intalación en Ubuntu 12.10<img src="img/009-ubuntu.png" width="62" height="59"></h2>
file04.html: <h3 align="left">Intalación en Ubuntu <img src="img/009-ubuntu.png" width="62" height="59"></h3>
file04.html: <h3 align="left">Intalación en Ubuntu <img src="img/009-ubuntu.png" width="62" height="59"></h3>

In this case you want to change a word in all the documents.

Solution

You can use sed with vi commands:

sed -i 's/<original>/<replaced>/g' 

In this case we can solve the problem with

sed -i 's/Intal/Instal/g' *.html
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s