[lug] simple text editing problem

Jeff Schroeder jeff at neobox.net
Thu Aug 22 09:46:06 MDT 2002


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

You could use vi (or a clone like Elvis) in conjunction with a find 
command...

vi `find -name "*.c" -exec grep -l <regexp> {} \;`

And in vi, do the search-and-replace as necessary.  To "remember" the 
search from day to day-- if you're just replacing the same stuff over 
and over-- I'd suggest using a "map" command and saving it in your 
~/.exrc file.  For example, put the following line in ~/.exrc:

map + :s/text to search for^M

(The last character is a control-M, which you enter by first pressing 
control-V and then control-M.)

HTH,
Jeff



More information about the LUG mailing list