regexp..prepending a line globally (Vi)

Daniel Smith - OPD Gang daniel at island.uu.net
Mon Jul 2 06:00:46 AEST 1990


	All my years in vi and this one stumps me!  I wanted
to make a real quick shell script, taken from the output
of an ls-lR on uunet.  So, I get these lines:

/usr/spool/ftp/comp.sources.unix/volume22/nn6.4:
part01.Z
part02.Z
part03.Z
part04.Z
.
.
. etc...

	So far so good.  Now what I wanted to do is take the first
line (with the path) and prepend it to every line with a regexp.  I know
how to do this quickly by hand and all that, but thought I should
be able to do this easily with something like:

	:g/\(.*spool.*\)/s/^part/\1\/part/g

	which is wrong.  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

	I'll do it by hand this time, but I'd really like to know
"how to capture a pattern on a given line, and then apply it on
other lines that match another pattern".  Thanks for any help.

	Oh, and before we get into editor wars...I am trying to learn
GNU Emacs...it's just hard to make the shift after 8 years of vi ;-)

				Daniel
-- 
   dansmith at well.sf.ca.us   daniel at island.uu.net   unicom!daniel at pacbell.com
ph: (415) 332 3278 (h), 491 1000 (w) disclaimer: Island's coffee was laced :-)



More information about the Comp.unix.questions mailing list