DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Search And Replace Over File(s) With Perl
A quick bit of Perl can come in handy if you have an old site to update that has no CMS, or something similar.
To change 'source' to 'destination' in all HTML files in the current directory:
perl -pi -e 's/source/destination/g' *.html
You could use this to update copyright notices, etc.. but bear in mind you need to stay with Perl/regex syntax, so escape those forward slashes, etc :)






Comments
Snippets Manager replied on Tue, 2007/01/23 - 5:15pm
Snippets Manager replied on Mon, 2012/05/07 - 2:20pm
Snippets Manager replied on Mon, 2006/02/20 - 8:08pm
sed -i -e 's/source/destination/g' *.htmlAdd -r if you need extended regexp in sed.Snippets Manager replied on Mon, 2006/02/20 - 8:08pm
sed -i -e 's/source/destination/g' *.htmlAdd -r if you need extended regexp in sed.