in-place replacement from command line

chris (2003-07-03 02:05:30)
7624 views
0 replies
To replace all occurences of the word "hello" with the word "harrow" in files in the current directory, use perl's in-place substitusion from the command line as follows:

perl -pi -e 's/hello/harrow/g' *.txt

note, the 'g' at the end makes it match [greedily|globally] - ie it will to multiple matches in a single line. You can add an 'i' for case insensitivity.

Full regular expressions can be used, and the *.txt can of course be *.html, *.anything, or just *


christo
comment