In-place string changing in files from the command line with "perl pie"

18 April, 2007 - 13:22

The standard unix/linux tools for filtering/changing strings (or patterns) in files from the commandline are sed and awk. But what if you want to change strings in-place in the files without the burden of creating new files and replacing the old ones afterwards?

The "perl pie" is a handy one-liner for these occasions:

perl -p -i -e 's/Jesus/Elvis/g' bible.txt

This will replace in file bible.txt all occurences of 'Jesus' with 'Elvis' in-place.

More info: