Return to Snippet

Revision: 16888
at August 18, 2009 11:49 by jessibird


Initial Code
perl -pi.bak -e "s/Old text/New text/g" file1 file2 file3

Initial URL
http://www.debian-administration.org/article/Performing_search_and_replace_operations_across_multiple_files

Initial Description
-p tells perl to assume a simple loop around the code we give it to run.

-i.bak tells perl that we wish to create backups of the files we modify with the suffix .bak.

-e "..." tells perl that we wish to execute the code inside the quotes.

And finally the file list is the list of files that we wish to operate upon.

Escape special characters such as ".", "?", "*", or "/" by preceding them with the "\" character.

Example: change "Bob" to "Steve" on all HTML files in the current directory:

perl -pi.bak -e "s/Bob/Steve/g" *.html

Initial Title
Search and replace across multiple files

Initial Tags


Initial Language
Perl