This simple yet powerful script scans a collection of files (HTML files in this one particular example case although any file type would do). It attempts to find a string described by a regular expression and then replace it with another. In simpler terms, it is a command-line "search and replace". Why command line? When a large number of static pages have to be changed similarly, only scripting is the answer.
Below is some template code. By varying the code, it is possible to add a file footer, add header information or fix a frequently-repeated (or duplicated) typo. For instance, one can replace all occurrences of "dogg" with "dog" in text files in the current directory.Have a glance at the following code (expressions changed to generic words):
To give an example that is practical, the code below adds an important link to the RSS feed on the site. The link is essentially appended to the elements in the header section.# add_header - change header of all files in the current directory
An extra script will apply the changes to all HTML files in the current directory (note that it might need changing to account for
Note that the full path of
Thanks to Toby Inkster for suggesting a way to handle regular expressions.
|This page was last modified on June 12th, 2005||Maintained by Roy Schestowitz|