Posted By

jessibird on 08/18/09


Tagged

Shell


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jessibird
icecreamboyy


Search and replace across multiple files


 / Published in: Perl
 

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

-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

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

Report this snippet  

You need to login to post a comment.