[ale] vim search/replace syntax request

Dow Hurst dphurst at uncg.edu
Thu Mar 10 10:36:26 EST 2011


In vim what you sent translates to my needs as listed below and works like a
charm!  Thanks for the information!

:6,14 s/^\(.\{84\}\)1\(.*\)$/\10\2/

Best wishes,
Dow
________________________________________________
Dow Hurst, Research Scientist
340 Sullivan Science Bldg., Dept. of Chem. and Biochem.
University of North Carolina at Greensboro
PO Box 26170 Greensboro, NC 27402-6170




On Thu, Mar 10, 2011 at 7:28 AM, Byron Jeff <byronjeff at mail.clayton.edu>wrote:

> On Thu, Mar 10, 2011 at 02:04:15AM -0500, Dow Hurst wrote:
>
> > I'd like to construct a vim based search and replace statement.  I want
> > to search between a set of line numbers for the 85th character on a line
> > and if it contains a "1" then turn it into a "0".  I just don't know how
> > to set up that particular search pattern and replace pattern.
>
> The following should work in vim. Not sure about raw vi:
>
> :%s/^\(.\{84\}\)1\(.*\)$/\10\2/
>
> Here is an expanded version with some backslashes eliminated for
> explanation:
>
> :%s/^ ( .{84} ) 1 ( .* ) $ / \1 0 \2 /
>
> The :%s/^ is the standard substitute all lines and mark the beginning of
> the line.
>
> The parens in the expression are grouping operators. Needs backslashes to
> mark as special operators. Each group captures and saves the match so that
> it can be reinserted in the substitution. The groups are numbered starting
> with 1.
>
> So the first group captures .{84} which matches exactly 84 charaters.
>
> The 1 matches the 1 in the 85th column.
>
> The .* is the second group which captures the rest of the line after the
> 85th character. Probably could get away without it (*). The $ is the end of
> the
> line.
>
> Once a line is matched then the substitution is pretty simple:
>
> The \1 is the first group which is the first 84 characters.
> the 0 substitutes for the 1.
> the \2 is the group for the rest of the line.
>
> (*) This should also work:
>
> :%s/^\(.\{84\}\)1/\10/
>
> Good Luck.
>
> BAJ
>
> >
> > It's been a long time since I've posted to the list.  It is nice to see
> the ALE group is flourishing.  I miss going to the meetings...
> >
> > Best wishes,
> > Dow
> > ________________________________________________
> > Dow Hurst, Research Scientist
> > 340 Sullivan Science Bldg., Dept. of Chem. and Biochem.
> > University of North Carolina at Greensboro
> > PO Box 26170 Greensboro, NC 27402-6170
> >
> >
>
> Content-Description: ATT00001..txt
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://mail.ale.org/mailman/listinfo/ale
> > See JOBS, ANNOUNCE and SCHOOLS lists at
> > http://mail.ale.org/mailman/listinfo
>
>
> --
> Byron A. Jeff
> Department Chair: IT/CS/CNET
> College of Information and Mathematical Sciences
> Clayton State University
> http://cims.clayton.edu/bjeff
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20110310/86dbfd4a/attachment-0001.html 


More information about the Ale mailing list