sed

Imagine you have a large file ( txt, php, html, anything ) and you want to replace all the words “ugly” with “beautiful”

This is the command:

CODE
$ sed -i ‘s/ugly/beautiful/g’ /home/bruno/old-friends/sue.txt

“sed” edits “-i in place ( on the spot ) and replaces the word “ugly with “beautiful” in the file “/home/bruno/old-friends/sue.txt”

do this for all files under a certain directory

CODE
$ find /home/bruno/old-friends -type f -exec sed -i ‘s/ugly/beautiful/g’ {} \;

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s