On Tue, Sep 30, 2014 at 11:44 AM, Craig Treleaven <ctrelea...@macports.org> wrote:
> I have only rudimentary acquaintance with sed and less with awk. I'd like > to learn more and this seemed like an opportunity to do so. From some > reading [1], I think sed'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? 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'd reach for perl/python/ruby first. 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: s/^ // t dataline s/ .*$// h b : dataline G s/^\(.*\)\n\(.*\)$/\2 \1/ # now starts with the package name and a space; put the rest of the processing here... You can see how painful it gets. (Also the above is untested.) Better to use a real language. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ macports-dev mailing list macports-dev@lists.macosforge.org https://lists.macosforge.org/mailman/listinfo/macports-dev