Node body search and replace Drush command

This is a command for the very useful Drupal Shell (Drush) module that lets you search and replace text in the body of a node using regular expressions. I wrote it when I was fixing broken links for the Center for Research Library’s web siter and got tired of having to visit a URL, click the edit link, replace the text, update the revision log, and click the save button.

Install this command as you would any other contributed command (for instance, you could put this file in your ~/.drush folder)

To learn how to use, check out the help text for the command by running drush help replace at the command line.

Example usage:

$ drush –url=http://www.crl.edu replace jstor-titles/economics-titles “/http:\/\/www.crl.edu\/jstortitles\/” “”

This replaces all instances of http://www.crl.edu/jstortitles with an empty string. Note that the syntax and escaping of the regular expressions are for those of PHP’s preg_replace function.

Download replace.drush