Ralph Shumaker wrote:
Stewart Stremler wrote:
begin quoting Ralph Shumaker as of Wed, Jan 31, 2007 at 12:32:21PM
-0800:
I want to know how to use vi to do search and replace. Is there
something easier to use than "help" to find out how?
I want to replace all instances of
"^[0-9][A-Z]" with
"^[0-9] [A-Z]".
:%s/^\([0-9]\)\([A-Z]\)/\1 \2/
: -> go to command mode
% -> for every line in the file
s -> substitute
/ -> delimit the parts of the substitution
^ -> start of line
\( -> start a group, must escape ( with \ because this is a retrofit
[0-9] -> pattern
\) -> end of the group
\( -> start a group
[A-Z] -> pattern
\) -> end of the group
/ -> end the first part
\1 -> contents of first group
\2 -> contents of second group
/ -> end of substitution
You assumed "^" is "start of line". It's not. I'm assuming I need to
My bad. I was tired and not thinking clearly. You assumed nothing. I
should have escaped the "^" in my example because I knew it signified
start of line in regular expressions. My bad.
Thanks again Stewart.
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list