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

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.

This entry was posted in System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).