>Or:
>       :%s/susank/susanr/g
>
>The differences:
>Ken's one says
>       for every line "g" containing susank "/susank/"
>               replace that "s//" with susanr "susanr/"
>               for all the occurences on the line "g"
>
>Mine says:
>       for every line "%" (which is shorthand for "1,$", which is from
>               line 1 to the last line "$") substitute susanr for susank
>               "s/susank/susanr/" for all the occurences on the line "g"
>
>Much the same functionally, utilising different syntax.

Well, might as well explain the whole hog:

        g/pattern/action

first marks the lines that match and then performs the action. The pattern
doesn't have to connected to the action. I could do:

        g/susank/s/^/ /

puts a space in front of every line containing susank somewhere.

        %action
or      1,$action

just attempts the action on every line.

You can even have both:

        1,20g/susank/s/^/ /

only attempts the marking on the first 20 lines and then does the action
on marked lines.

The concept of two phases in the g command, marking and then action,
is important even if it isn't actually implemented that way internally
because actions can create additional lines that would match if a
one-phase interpretation were applied.
--
SLUG - Sydney Linux Users Group Mailing List - http://www.slug.org.au
To unsubscribe send email to [EMAIL PROTECTED] with
unsubscribe in the text

Reply via email to