cordump.com

TIP: search and replace, in place, across multiple files

by daven on Jan.20, 2009, under Automation, General System Administration, Quick Tips

Ever have that need to change one little thing in a bunch of files? You know after you accidentally misspelled your Boss’s name as “Marvin Blowhard” on every page of the Company website.
Now you could open up each file in vi and find every reference to Mr. Blowhard to Joe Smith, even using search & replace
s/Marvin Blowhard/Joe Smith/ inside vi get’s kind of tedious after a while. That joke doesn’t seem so funny now, does it?
Now consider a little BASH and sed foo

for i in `ls *.html`; do sed "s:Marvin Blowhard:Joe Smith:g" $i >temp;mv temp $i; done

All nice and done so you can get back to planning your next BOFH moment, like sending him in the into the server room with a flash light to look for breaks in the fiber runs.


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...