[NBLUG/talk] command line search/replace

S. Saunders sms at sonic.net
Fri Nov 3 22:57:13 PST 2006


On Thu, November 2, 2006 16:26, Barry Stump wrote:

> Hi all--
>
> I have a situation where I wish to replace one string with another in
> a project that is comprised of several hundred code files in several
> directories.  The thing is, I would like to be asked confirmation (and
> shown some context) for each match, as I suspect some matches need to
> be left alone.  Are there any command line gurus here who can show me
> how to make a find/grep/sed combo interactive, or shall I open all
> matching files in vim and use :%s/this/that/gc on every buffer?  Any
> other ideas?
>
> -Barry

I see you've already solved your problem.  Just thought I'd mention, if
you use linux (or have Gnu's grep on a commercial unix) -- which seems
very likely as you specify "vim" not "vi"... contextual grep!

grep -C  or grep -# (where "#" is a number).

Mmmm... tasty!

You can always script with a read/if, case, etc.

I see 3 cases, off hand:  YES, change; NO, do not change; invoke a full
vim to examine further.

All of which is beside the point, now... ;-)
But I mention anyhow, in case archive-miners look for similar questions.


- Steve S.





More information about the talk mailing list