Unix: Replace text in multiple files and subfolders

I have  thousands of HTML pages that need to be updated – I just have to swap a couple of lines. I was wondering how to do it all at once and in subdirectories as well.

Here’s what worked:

for mFile in `find . ! -type d -name ‘*.html’` do
sed -i ‘s/text1/replacement1/g’  $mFile

sed -i ‘s/text2/replacement2/g’  $mFile

sed -i ‘s/text3/replacement3/g’  $mFile
done

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 )

Facebook photo

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

Connecting to %s