regexp..prepending a line globally (Vi)

Randal Schwartz merlyn at iwarp.intel.com
Tue Jul 3 02:49:49 AEST 1990


In article <1772 at island.uu.net>, daniel at island (Daniel Smith - OPD Gang) writes:
| 
| 	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.

You can't do it in vi without resorting to some macro trickery.  (Of
course, the vi hackers will now come out of the woodwork to prove me
wrong... after all, this *is* Usenet. :-)

In Perl, it'd be:

perl -ne 'if (/^(.*):$/) { $pre = $1; } else { print "$pre/$_"; }'

Just another Perl hacker,
-- 
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III      |
| merlyn at iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/



More information about the Comp.unix.questions mailing list