regexp..prepending a line globally (Vi)

Leo de Wit leo at ehviea.ine.philips.nl
Wed Jul 4 01:11:30 AEST 1990


In article <8571 at jpl-devvax.JPL.NASA.GOV> lwall at jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
|In article <7047 at star.cs.vu.nl> maart at cs.vu.nl (Maarten Litmaath) writes:
|: 
|: Not so trivial, I think.  The following sh/sed solution works.
|: Try to figure it out!
[about 18 lines of sed script omitted]
|
|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.

OK, Larry, you asked for it :-)

sed '/spool/h
//d
G
s/\(.*\)\n\(.*\):/\2\/\1/' $*

Trivial, indeed.

    Leo.



More information about the Comp.unix.questions mailing list