Path: utzoo!attcan!uunet!mcsun!tuvie!iiasa!wnp From: wnp@iiasa.AT (wolf paul) Newsgroups: comp.editors Subject: Re: ex search & substitution question Message-ID: <832@iiasa.UUCP> Date: 8 Aug 90 08:46:03 GMT References: <3440001@hprnd.HP.COM> <26814@nigel.ee.udel.edu> <1990Aug07.174235.28911@hoss.unl.edu> Reply-To: wnp@iiasa.UUCP (wolf paul) Organization: IIASA, Laxenburg/Vienna, Austria, Europe Lines: 38 In article <1990Aug07.174235.28911@hoss.unl.edu> sanjiv@hoss.unl.edu (Sanjiv K. Bhatia) writes: >In article <3440001@hprnd.HP.COM> brent@hprnd.HP.COM (Brent McInnis) writes: >>But to perform it on a *range* of lines (say, lines 10 thru 20), I >>*want* to say >>:10,20/^#[iut]55/s/55/71/ > >Here is my $0.02 worth. I prefer to use the substitute command 's'. > >:10,20s/^#[iut]55/71/ NO, that won't work. It will replace the entire matched string #[iut]55 with just the two digits 71. You need to save the first part of the matched string using the \( \) operators, and then interpolate them in the substitution string with \1, like this: :10,20s/^\(#[iut]\)55/\177/ This says, in effect: "At the beginning of the line, locate and save '#[iut]', if it is followed by '55'. Substitute for the entire matched string the saved portion followed by 71." The \( \) operators save the matched string specified by the RE between them for later interpolation into the substitute string; if you use just one pair of \( \), the interpolation takes the form '\1', if you use several pairs successively, use '\1', '\2', etc. Hope this helps. -- Wolf N. Paul, Int. Institute for Applied Systems Analysis (IIASA) Schloss Laxenburg, Schlossplatz 1, A - 2361 Laxenburg, Austria, Europe PHONE: +43-2236-71521-465 FAX: +43-2236-71313 UUCP: uunet!iiasa.at!wnp INTERNET: wnp%iiasa.at@uunet.uu.net BITNET: tuvie!iiasa!wnp@awiuni01.BITNET