Happy-the-monk has asked for the wisdom of the Perl Monks concerning the following question:
Today I found the task to change all occurences of a string in some of a larger sum of files and remembered perlrun, which I don't do very often. After having backupped all files in question (which proved to be a good idea later), I did a
perl -pi -e 's/(:Timeplaner):Projekt,/$1$1,/' *
and naively expected it to change the 115 (out of 432) files that needed the change.
But of course it did more than just that.
All files were changed, and their old access date was lost (read: except for in the backup, d'oh!).
Now I am wondering what would be the nicest way of doing the task to only change those files actually containing the string I am looking for, leaving the others untouched and still use something comparatively simple as perl -pi?
Cheers, Sören
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: "Change, but don't touch" or naive use of perl -pi
by merlyn (Sage) on Sep 29, 2004 at 10:49 UTC | |
|
Re: "Change, but don't touch" or naive use of perl -pi
by Anonymous Monk on Sep 29, 2004 at 08:47 UTC | |
by Happy-the-monk (Canon) on Sep 29, 2004 at 08:52 UTC | |
|
Re: "Change, but don't touch" or naive use of perl -pi
by Your Mother (Archbishop) on Sep 29, 2004 at 21:24 UTC |