OT: sed/awk pointers needed

Craig Treleaven ctreleaven at macports.org
Tue Sep 30 13:02:03 PDT 2014


At 2:27 PM -0400 9/30/14, Lawrence Velázquez wrote:
>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
>%
>
>
>Attachment converted: Macintosh HD:variants.sed (    /    ) (0342ACEF)

Thank you!  Off list, I was pointed to a sample 
Awk program* that reformats a 'billing report'. 
That helped; you've given me a complete solution!

* http://www.programmingforums.org/post226750.html

APL used to have the reputation as a "write-only" 
language.  This script is pretty close to that 
ideal.  ;)

Craig


More information about the macports-dev mailing list