Mass File Edit

posted August 29th 2005 at 2007 EDT in All

Often times I want to edit a whole slew of files at once, changing only a simple string. But it's the same change in all the files.

The solution for this has eluded me till now (worst yet.. it's a simple solution. A classic one liner.)


perl -pi.bak -e 's/oldstring/newstring/' *.py
 

Simply put this changes every ocurence of "oldstring" to "newstring" in *.py saving the original files as *.py.bak

then verify it did what you wanted and delete the .bak files

2 Responses

  1. #1 eokyere
    4 years, 11 months ago

    learn sed, learn awk, then learn to make them make coffee :)

    eokyere

  2. #2 jehiah
    4 years, 11 months ago

    awk I know (and love). Great for digging through log files. sed I still need to work on.