regexp..prepending a line globally (Vi)

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Tue Jul 3 04:47:23 AEST 1990


In article <7047 at star.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
: In article <1772 at island.uu.net>,
: 	daniel at 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 at 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.



More information about the Comp.unix.questions mailing list