OT: sed/awk pointers needed

Lawrence Velázquez larryv at macports.org
Tue Sep 30 11:27:46 PDT 2014


On Sep 30, 2014, at 12:00 PM, Brandon Allbery <allbery.b at gmail.com> wrote:

> On Tue, Sep 30, 2014 at 11:44 AM, Craig Treleaven <ctreleaven at 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.

Yup. Sed is not a great tool for this sort of thing; the functionality it provides is ill-suited for complex conditionals and branching. You'll regret writing the script as soon as you go to read/edit it in a week or month.

vq

---------->8----------

That being said, I have masochistic tendencies.

% port variants php53-mysql php54-mysql | sed -nf variants.sed
php53-mysql	mariadb	N
php53-mysql	mysql4	N
php53-mysql	mysql5	N
php53-mysql	mysql51	N
php53-mysql	mysql55	N
php53-mysql	mysql56	N
php53-mysql	mysqlnd	Default
php53-mysql	percona	N
php54-mysql	mariadb	N
php54-mysql	mysql4	N
php54-mysql	mysql5	N
php54-mysql	mysql51	N
php54-mysql	mysql55	N
php54-mysql	mysql56	N
php54-mysql	mysqlnd	Default
php54-mysql	percona	N
%

-------------- next part --------------
A non-text attachment was scrubbed...
Name: variants.sed
Type: application/octet-stream
Size: 529 bytes
Desc: not available
URL: <https://lists.macosforge.org/pipermail/macports-dev/attachments/20140930/c8f1bcde/attachment.obj>


More information about the macports-dev mailing list