Python Mass Editor is a Python module that implements a python mass editor class to process multiple files using Python code. The modification(s) is (are) shown on stdout as a diff output. One can then modify the target file(s) in place with the -w/--write option.
You probably will need to know the basics of the Python re module (regular expressions).
usage: massedit.py [-h] [-v] [-w] [-V] [-e EXPRESSIONS] file [file ...]
Python based mass file editor
file file to process with the expression. Modified in
-h, --help show this help message and exit
-v, --version show program's version number and exit
-w, --write modify target file(s) in place
-V, --verbose increases log verbosity (can be specified multiple
-e EXPRESSIONS, --expression EXPRESSIONS
Python expressions to be applied on all files. Use the
line variable to reference the current line.
example: massedit.py -e "re.sub('failIf', 'assertFalse', line)" test*.py
or if massedit is installed as a package (from pypi for instance) :
python -mmassedit -e "re.sub('assertEquals', 'assertEqual', line)" test_pre_python_33.py
Download massedit.py from http://github.com/elmotec/massedit or :
pip install massedit
What's New in This Release: [ read full changelog ]
· Added massedit.edit_files function to ease usage as library instead of as a command line tool (suggested by Maxim Veksler).