Tags

, ,

Learned a bit of sed today when there was a need to search and replace a given text in some n files.

$ sed -e 's/TEXT_TO_FIND/TEXT_TO_REPLACE/g' SRCFILENAME > DESTFILENAME

Need to use -i instead of -e if we want to do the replace operation “in place”. There is also an option to backup the source file when doing this !

To do the same for a given set of html files, I used a combination of find and xargs and also the -i switch for the sed command:

$ find -iname '*.html' -print0 | xargs -0 sed -i 's/TEXT_TO_FIND/TEXT_TO_REPLACE/g'

Advertisements