[Project_owners] AWK related question

Michael Vincent van Rantwijk, MultiZilla mv_van_rantwijk at yahoo.com
Thu Aug 30 09:15:28 PDT 2007

Atte Kemppilä wrote:
> On Wed August 29 2007 16:33, Michael Vincent van Rantwijk wrote:
>> Atte Kemppilä wrote:
>>> On Wed August 29 2007 08:54, Michael Vincent van Rantwijk wrote:
>>>> I can do nice things with AWK these days, but the one thing I still
>>>> don't get is how I should print the matching data of a search/regex like
>>>> for example: /foobar/ { print } as in how do I get it to dump "foobar"
>>>> (where foobar can be anything I need)?
>>> Not quite sure that I understood the question but do you mean this:
>> Let's take the following example:
>> <description>Some Random Text</description>
>> should become:
>> <!ENTITY .description "Some Random Text">
>> Note: I want to do something similar for:
>> label="A Random Label Attribute"
>> accesskey="A Random Accesskey Attribute"
>> label value="A Random Value Attribute"
>> Which should be come:
>> <!ENTITY .label "A Random Label Attribute">
>> <!ENTITY .accesskey "A Random Accesskey Attribute">
>> <!ENTITY .value "A Random Value Attribute">
> $ gawk --version
> GNU Awk 3.1.5
> $ echo '<label>text</label>' | gawk 'match($0, /<(description|label|accesskey|
> value)>([^<]*)<\/[^>]*>/, arr) { print "<!ENTITY ." arr[1] " \"" arr[2] 
> "\">" }'
> <!ENTITY .label "text">
> Tag matching is kind of simplistic in the above. You could make it better 
> using ranges. 

> But then again, why are you using awk with xml data. 

Because I need to learn and master AWK scripting, and a.s.a.p.

> Wouldn't xsl be The Right Tool for this.

XSLT can be used when I want to use it from let's say mozdev.org and 
generate .dtd files on the fly, using either the ID's or the first N 
characters of the text (without spaces) as entity names, but not when I 
*have* to run it as a shell service.

Michael Vincent van Rantwijk
- MultiZilla Project Team Lead
- XUL Boot Camp Staff member (ActiveState Training Partner)
- iPhone Application Developer

More information about the Project_owners mailing list