Never been to DZone Snippets before?

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

About this user

Peter Cooperx http://www.petercooper.co.uk/

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

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 :)

Doing a find and replace on Rails objects from the console

Content.find(:all).each { |x| x.content.gsub!(/\bWebpage/i, "web page"); x.save; }
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS