Here is a sample of the OSS Consulting services we provide:

  • Open Source Technology Strategy
  • Open Source Application Development
  • Custom Open Source Programming and Integration
  • Open Source Web Performance
  • Open Source Web site Security Analysis
  • Integration with Windows and Open Source Systems
  • Open Source Mail systems Setup/Integration
Home  |  Blog  

Neptune Web Blog

HTML Search and Replace Tool

Tuesday, January 12th, 2010

SysAdmin March 2006 HTML Search and Replace ArticleIn March 2006, Neptune Web developed a simple command-line, Open Source, search and replace utility for performing searching 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.pl.

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:

e.g. 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 -@ backup.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 dwreplace.pl 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 neptuneweb.com.

Charlie

 

Add a Comment:

Your Name (shown on posting):

Your Email (not shown on posting):

Your Comment:
Security:

Comments


From: john dunn
Posted: Wednesday, January 13th, 2010 - 12:42 pm EST

Thanks for the script. It really helps to have a handy command line search and replace script around.