Re: How to apply a list of regex replaces to multiple files?
Xah <xahlee <at> gmail.com>
2008-07-01 23:25:28 GMT
On Jun 30, 6:50 pm, "michael.l" <michael.lom... <at> gmail.com> wrote:
>... I have about 900 documents to which I need to apply a
> list of maybe 40 separate regex search and replaces. I would like to
> feed a list of the regex expressions and replacements to emacs and
> have it applied to a directory of the files. Any solutions? Keyboard
> macros don't seem like the right solution....
if you want to do it in Python, here's the full script:
http://xahlee.org/perl-python/findreplace_multi_pairs.html
if you want to do it in Perl, here's the full script:
http://xahlee.org/perl-python/find_replace_perl.html
If you want to do it in emacs, it's even easier.
If you only have 1 single find-replace pair, then it's is build in.
Just go to dired, mark the files, type Q (which calls dired-do-query-
replace-regexp). Aften done, type ibuffer then type “* U” to mark all
unsaved, then “S” to save them all, type “D” to close all opened
files. For some full detailed tutorial, see
http://xahlee.org/emacs/find_replace_inter.html
If you have multiple pairs of find-replace, then you need a script.
Like this:
; open a file, process it, save, close it
(defun my-process-file (fpath)
"process the file at fullpath fpath ..."
(Continue reading)