in reply to search and replace text in multiple files in a directory
What I do is I have a script in my ~/bin directory called fixfile.pl that looks like this:
!/usr/bin/perl -p -i s/expression_to_replace/replacement_expression/gs;
My program is much longer, because each time I find a regex that works I leave it in the program, commented, and add my new regex. That way I create a library of useful regexes. To use the program I just go to the directory I want to make the changes in, and run (for your example) fixfile.pl *.html and the regex is performed on all files with the extension .html. The reason I find this useful is because I can leverage the power of a perl one-liner without losing the record of what I've been doing, and it lets me use my familiar shell globbing operators.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search and replace text in multiple files in a directory
by Anonymous Monk on Apr 04, 2005 at 10:52 UTC |