sed -i.bak 's/foo/bar/g' *.cpp
ADDITION:
I Often find I want to just replace whole words. The way you do this will depend on the version of sed you're using.
This works for me on OS X
sed -i.bak 's/[[:<:]]foo[[:>:]]/bar/g' *.cpp
sed -i.bak 's/\<foo\>/bar/g' *.cpp
I once had to convert a large amount of Ada code to C (about 30,000 lines in about 100 source files).
ReplyDeleteAmazing how far a fairly ugly sed script could go in doing that. A few things like array indexing needed to be done by hand - Ada uses round brackets () for both arrays and function calls and uses context to figure out which means what. Doing that automatically requires a proper parser - a place I did not want to go.
Sed is *very neat* once you know a few regex's.