[CLUE-Tech] find & replace on a tree of files
David L. Willson
DLWillson at TheGeek.NU
Mon Nov 1 15:00:25 MST 2004
Never let it be said that I missed an opportunity to show publically that I am
the slow kid...
I just figgered out how to do this thing, and it seemed cool to me, so I'm
sending it on to you.
The following one-liner is polluted with whacks to show you that it really
should be all-on-one-line. Actually, you can use it all-on-one-line, or with a
whack at the end of each sub-line, like you see here.
What it does is the sub-tree beginning here (.), looking for files matching the
spec '*.hay', which could be any spec. The one I use most often is, sadly,
'*.asp'. Then, for each matching file, it finds each instance of 'old_needle'
and replaces that text with 'new_needle', globally.
Incidentally, don't mess with the space-whack-semicolon at the end of the
command, it matters a lot.
find . \
-iname '*.hay' \
-exec \
sed -e s/old_needle/new_needle/g -i.backup {} \;
____________________
David L. Willson
tel://720.333.LANS
Linux+ A+ Net+ MCSE
-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/
More information about the clue-tech
mailing list