CoolComputing Logo
Coupons/Deals  ·  New Promo Codes/Coupons  · October 18, 2018

Use perl to search and replace text in multiple files

Posted on Tuesday, August 7, 2001 @ 01:23:31 PM CDT by David Yee [] [read 15207 times]

 
Tips: Linux/Unix world
You can use regular expressions within perl to do a search and replace of text on multiple files on the command line. Here's the general syntax:

perl -e "s/old_string/new_string/g;" -pi.bak $(find name_of directory -type f)

This will also make a backup of the original files by making a copy each with the .bak extension. Here are two examples:

Relace all instances of shtml with php on all the files in the current directory:
perl -e "s/shtml/php/g;" -pi.bak $(find . -type f)

Replace all ssi virtual include calls with php include:
perl -e "s/<!--#include virtual="./menu.html" -->/<?php include("menu.inc"); ?>/g;" -pi.bak $(find . -type f)





Please rate this article or post a brief review of Use perl to search and replace text in multiple files or comment on benchmark/performance, features, availability, price or anything else regarding Use perl to search and replace text in multiple files. Thanks!

Use Perl To Search And Replace Text In Multiple Files Rating: 2.3/5 (19 votes cast)

Your Name:
I have read and agreed to the Review Posting Agreement.
Review Title:
Comment/Review: