regexp..prepending a line globally (Vi)

Leslie Mikesell les at chinet.chi.il.us
Wed Jul 4 01:59:41 AEST 1990


In article <3235 at d75.UUCP> eli at reed.UUCP (Eli Taub/100000) writes:

[how to do this in vi]:
>>/usr/spool/ftp/comp.sources.unix/volume22/nn6.4:
>>part01.Z
>>part02.Z
>Comments deleted ...

>>What I want to end up with is:
>>/usr/spool/ftp/comp.sources.unix/volume22/nn6.4/part01.Z
>>/usr/spool/ftp/comp.sources.unix/volume22/nn6.4/part02.Z
   >....
   >But since you asked for it ...:
   >$s/$/^M:/
   >g/^.*:$/s @^\(.*\):$@.,/:/-1 s!^!\1/!@ \
   >d a \
   >*a

Good grief!
Just edit the first line into the command for the transformation, delete
it into a register, and execute the register.  This gives you a series
of steps you can undo if you mis-type something.

edit to:
:%s,^,/usr/spool/ftp/comp.sources.unix/volume22/nn6.4/,
with the cursor on that line, type "add  (delete to register a)
then @a   (execute register a)
if it doesn't look right, just u (undo) "aP (put back from register a)
and try again.  The only problem to watch for with this approach is
that you need an extra level of ^V quoting for any special characters
(one to get them into the edit buffer, one to get them into the command).

Les Mikesell
  les at chinet.chi.il.us



More information about the Comp.unix.questions mailing list