Wednesday, January 16, 2008

Mass substitution with Perl Command Line

For changing all occurrences of a several expression in a file, Perl with command line options can be very helpful. The following shows a pretty general example:

$> perl -i.bck -ep 's/search_term/replace_with/g' filename

The above command will check the "filename" file and, replace all occurences of "search_term" with the "replace_with" term. "-i" option tells Perl to backup the file with a ".bck" extension before any operation.

No comments: