[ale] HOW2->automate search/replace text in ALL *.c files in Tree?

Christopher christopher at bergeron.com
Sun Nov 26 16:15:49 EST 2000


There's a program called streplace (it can be found on ebiblio) that has a
recursive function.  It's a command line program that could easily be called from
any shell script.  It complements grep, sed and awk nicely.

The syntax is similar to:   streplace "stringa" "stringb" filename [-R]


Cheers,
Christopher
gridforge.com

James CE Johnson wrote:

> 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.

--
To unsubscribe: mail majordomo at ale.org with "unsubscribe ale" in message body.





More information about the Ale mailing list