20130925 search and replace recursively - plembo/onemoretech GitHub Wiki

title: Search and replace recursively link: https://onemoretech.wordpress.com/2013/09/25/search-and-replace-recursively/ author: phil2nc description: post_id: 6402 created: 2013/09/25 11:03:11 created_gmt: 2013/09/25 15:03:11 comment_status: closed post_name: search-and-replace-recursively status: publish post_type: post

Search and replace recursively

My usual method of doing search and replace on a bunch of files is with the "perl -pi -e 's/foo/bar/g'" trick. Sometimes you need a method with a bit more finesse. There, I did it. I used the "f" word in a post. Sorry. Just more proof that system programming is really much closer to the culinary than the visual arts. Here's a nice one-liner I found over on superuser.com:

find . -type f -name "*.htm" -exec sed -i '' \
-e 's/dexample/texample/g' {} +

Used it to change the host name urls embedded in a few dozen html files from their development to test environment identities. Yeah, the guy comes from the Windows side of the house.

Copyright 2004-2019 Phil Lembo