Xref: utzoo comp.unix.questions:23456 comp.lang.perl:1701 Path: utzoo!attcan!uunet!decwrl!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.unix.questions,comp.lang.perl Subject: Re: regexp..prepending a line globally (Vi) Message-ID: <8571@jpl-devvax.JPL.NASA.GOV> Date: 2 Jul 90 18:47:23 GMT References: <1772@island.uu.net> <7047@star.cs.vu.nl> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 60 In article <7047@star.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: : In article <1772@island.uu.net>, : daniel@island.uu.net (Daniel Smith - OPD Gang) writes: : )... : )/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. [...] : : Not so trivial, I think. The following sh/sed solution works. : Try to figure it out! : --------------------cut here-------------------- : SED=' : /spool/{ : : dir : s/:$/\// : h : : file : n : /spool/b dir : H : g : s/\n// : p : x : s/\n.*// : x : b file : } : p : ' : : sed -n "$SED" ls-output-file Which just goes to show ya... Real programmers can write assembly code in any language. :-) :-) :-) For those who believe in the waterbed theory of language complexity, how 'bout: #!/usr/bin/perl -p if (s#^(/.*):\n##) { $prefix = $1; } else { s#^#$prefix/#; } Fairly trivial, I think. Larry Wall lwall@jpl-devvax.jpl.nasa.gov P.S. It's not your fault, Maarten--if you push a waterbed down in one spot, it just naturally goes up somewhere else.