[lug] simple text editing problem

Tom Tromey tromey at redhat.com
Thu Aug 22 11:51:49 MDT 2002


>>>>> "Daniel" == Daniel Webb <webb at danielwebb.us> writes:

Daniel> I need to find and replace text from around 10,000 lines of c
Daniel> code in around 50 files in several directory trees.  I'm going
Daniel> to have to do this quite a few times, so the solution needs to
Daniel> be able to use "find" as the input for which files to load, or
Daniel> else remember from one day to the next which files I'm
Daniel> interested in.  Also, it has to be interactive, since I won't
Daniel> always be able to tell if I need to do the replace without
Daniel> context.

Daniel> Probably Emacs can do it, but I don't know Emacs yet.

Time to learn!

The way to solve this in Emacs is to use M-x tags-query-replace.  This
function is like query-replace but it sequentially visits every file
in your current tags file.

So you would:

find . -name '*.[ch]' -print | etags -
M-x visit-tags-table (then specify tags table you just made)
M-x tags-query-replace

IMHO it's really worth your time to become an expert with one of the
major editors.  I've never regretted the time I put into learning
Emacs.

Tom



More information about the LUG mailing list