<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Sep 30, 2014 at 11:44 AM, Craig Treleaven <span dir="ltr">&lt;<a href="mailto:ctreleaven@macports.org" target="_blank">ctreleaven@macports.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I have only rudimentary acquaintance with sed and less with awk.  I&#39;d like to learn more and this seemed like an opportunity to do so. From some reading [1], I think sed&#39;s Hold buffer is the way to extract the port name and insert it onto the line with each of the variants.  But the tutorial only uses the hold buffer for full lines; not just, say, the first word of the line.  Is this possible?  How does one do that?</blockquote></div><br>Very, very painfully. I think I could do it, with a LOT of fiddling, but would very much prefer to use a more appropriate tool. awk is somewhat better, but I&#39;d reach for perl/python/ruby first.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Very roughly, the trick is to chop the line down to the first word, save it to the hold buffer, then on subsequent lines append hold space to pattern space, swap the line around the embedded newline that gets inserted before the appendage, then replace that newline with a space. Use branch testing to detect the difference between the two kinds of lines: </div><div class="gmail_extra"><br></div><div class="gmail_extra">    s/^  //</div><div class="gmail_extra">    t dataline</div><div class="gmail_extra">    s/ .*$//</div><div class="gmail_extra">    h</div><div class="gmail_extra">    b</div><div class="gmail_extra">    : dataline</div><div class="gmail_extra">    G</div><div class="gmail_extra">    s/^\(.*\)\n\(.*\)$/\2 \1/</div><div class="gmail_extra">    # now starts with the package name and a space; put the rest of the processing here...</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div>You can see how painful it gets. (Also the above is untested.) Better to use a real language.</div><div><br></div>-- <br><div dir="ltr"><div>brandon s allbery kf8nh                               sine nomine associates</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a>                                  <a href="mailto:ballbery@sinenomine.net" target="_blank">ballbery@sinenomine.net</a></div><div>unix, openafs, kerberos, infrastructure, xmonad        <a href="http://sinenomine.net" target="_blank">http://sinenomine.net</a></div></div>
</div></div>