Mass File Edit

by @jehiah on 2005-08-29 20:07UTC
Filed under: 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]
perl -pi.bak -e 's/oldstring/newstring/' *.py
[/perl]

Simply put this changes every occurrence 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

Subscribe via RSS ı Email
Jehiah Czebotar