Xref: utzoo comp.unix.questions:23446 comp.lang.perl:1696 Path: utzoo!attcan!uunet!cs.utexas.edu!uwm.edu!ogicse!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions,comp.lang.perl Subject: Re: regexp..prepending a line globally (Vi) Message-ID: <1990Jul2.164949.1677@iwarp.intel.com> Date: 2 Jul 90 16:49:49 GMT References: <1772@island.uu.net> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 32 In-Reply-To: daniel@island.uu.net (Daniel Smith - OPD Gang) In article <1772@island.uu.net>, daniel@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@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/