bulk search and replace on unix using perl

This post was written 6 years ago.
Mon, 14 Aug 2006
here's a example of how you might do a bulk search and replace on unix - here i'm replacing all occurences of old style br tags with xhtml br tags:

perl -pi -e 's@<br>@<br />@g' * (this will replace all instances in all files in the current directory)

find . -type f | xargs perl -pi -e 's@<br>@<br />@g' (this version will search subdirectories too)

EDIT: remember that bulk search and replace can be dangerous, and also bear in mind that if you use subversion like we do, the method described above will affect the .svn files too. This appears to be a BAD THING
This post was written 6 years ago, which in internet time is really, really old. This means that what is written above, and the links contained within, may now be obsolete, inaccurate or wildly out of context, so please bear that in mind :)
Tags: linux /
Comments
blog comments powered by Disqus