[ale] HOW2->automate search/replace text in ALL *.c files in Tree?
James CE Johnson
jcej at tragus.org
Sun Nov 26 11:25:05 EST 2000
Wandered Inn wrote:
> Courtney Thomas wrote:
> >
> > Happy Holidays !
> >
> > I know how to do a find/replace in a single file using Xemacs but not
> > how to do a find/replace on all files in a Tree ? Any help here ?
> >
> > Also, perl is available, but I'd prefer a xemacs answer as I plan on
> > this environment, unless there's a better environment. How 'bout it ?
>
> Not emacs, but it works:
>
> for fn in $(find . -name '*.c' -print); do
>
> sed 's/FIND_THIS/CHANGE_TO_THIS/g' $fn > /tmp/$fn
> # note, original file is left if /tmp (backup)
> cp /tmp/$fn $fn
> done
I think the Perl solution is probably more efficient:
perl -p -i -e 's/FromThis/ToThis/g' $(find . -name '*.c')
At least, it doesn't use all those temp files. If you wanted to keep a backup
copy of each file you could do:
perl -p -i~ -e 's/FromThis/ToThis/g' $(find . -name '*.c')
Sorry I don't know the xemacs answer though.
--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.
More information about the Ale
mailing list