Neptune Web | Boston-based digital marketing agency: Website Design, Website Services, SEO, Marketing Automation Neptune Web

Update to command line HTML search and replace tool

In March 2006, Neptune Web developed a simple UNIX command-line, open source search-and-replace utility for performing searches against free-form HTML files.

We knew it would be useful to others, so we wrote a magazine article about it. The article appeared in Sysadmin Magazine, as Better Find and Replace on HTML Content.The latest version of the script can be found here:

Dwreplace isn't something that we need to change much. It does the job and doesn't require much maintenance. However, there have been a few updates since the article appeared.

We have added the --null option, which allows you to run find in conjunction with dwreplace. e.g.

find . -print0 | dwreplace --rfile=blah.rfile --null

However, you don't need to null terminated filenames to stdin (I prefer this method instead, because its simpler). You can also use regular newline terminated filenames like this:

find . -print | dwreplace --ffile=blah.rfile                  

This works just like "zip" using the -@ option. (-@ is one of my favorite options to zip which you should know about if you don't already)

For example:

# make a backup, reading from newline terminated lines

find . | zip -@

# then list the files and replace the HTML text.

zip -l | dwreplace --ffile=blah.rfile

There is also a new --m option, which shows matches only, do not show unmatched files. Thanks for Joseph Lamoree for that contribution.

Run dwreplace --e

to see an example rfile and without any options to see the options available.

The script is a small contribution to Open Source, but it proves to be a useful utility which people use again and again. Last year, I was surprised to have someone send me a free T-shirt. The person ran a bamboo clothing store e-commerce site, and the script saved him a few hours.

If you have any contributions, questions or comments (or free t-shirts) please leave below, or email me at charles dot dalsass at

Neptune Web is a full-service Boston-area interactive web and digital marketing agency with expertise in Website Design, Web Development, Digital Marketing Strategy and Execution.

We look forward to your comments and would be most happy to address and help solve any Digital Marketing or Website Design & Development challenges you may have.

comments powered by Disqus