global search and replace
pll at lanminds.com
pll at lanminds.com
Tue May 13 10:21:21 EDT 2003
In a message dated: 13 May 2003 09:41:23 EDT
Greg Rundlett said:
>It has been so long since I used perl, that I have to dig through my
>books and old code snippets even to find and understand the recipes that
>I come across.
>
>How do you do this?
Well, assuming that all the files are under a single hierarchy, you
could do something like this:
for i in `find ./ -type f -print | xargs grep foo | cut -f1 -d: | sort -u `
do
perl -i.bak -anpe '$_ =~ s/foo/bar/g' $i
done
Of course, there's probably an easier way using the perl File::Find
method, but this is quick and dirty.
Oh, btw, the above will result in all the original files being moved
to *.bak. If you do not want this, remove the '-i.bak' above.
--
Seeya,
Paul
--
Key fingerprint = 1660 FECC 5D21 D286 F853 E808 BB07 9239 53F1 28EE
It may look like I'm just sitting here doing nothing,
but I'm really actively waiting for all my problems to go away.
If you're not having fun, you're not doing it right!
More information about the gnhlug-discuss
mailing list