[Clam-devel] New script for doing batch substitutions

Pau Arumi parumi at iua.upf.edu
Thu Oct 25 05:27:13 PDT 2007


Every now and then I find the need to do automatic substitutions to a 
number of files in batch.
To help on this task I've commited a python script:

CLAM/scripts/batchSubstitute.py

Let's see an example (not CLAM related, neither C++ related but will do 
the job as an example). Say you want to do wiki formatting like: 
substitute [http://google.com] -> <a 
href='http://google.com'>http://google.com</a>, {{{ -> <pre>, }}} -> </pre>

Then just edit these two variables in the script:

inlineSubstitutions = [
    (r"\[(\S*)\]", r"<a href='\1'>\1</a>"),
    (r"{{{", r"<pre>"),
    (r"}}}", r"</pre>"),
]
filesToSubstitute = [
    "*.txt",
    "../*.wiki",
]

The script also contains a bunch of examples to easily remember how to 
use regular expressions.
But use with caution since it overwrite the file!

Cheers,

Pau




More information about the clam-devel mailing list