[NBLUG/talk] command line search/replace

Barry Stump barry.stump at gmail.com
Sat Nov 4 07:50:26 PST 2006


I found the hard part with grep is to make the process interactive for
each match, rather than each matching file.  Vim makes this easy with
the /c switch for the substitute command.

-Barry

On 11/3/06, S. Saunders <sms at sonic.net> wrote:
>
> 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.
>
>
>
> _______________________________________________
> talk mailing list
> talk at nblug.org
> http://nblug.org/cgi-bin/mailman/listinfo/talk
>



More information about the talk mailing list