Re: AW: Scripting: processing stanzas

From: Bruce Harvey (BruceH@ROUTESCAPE.COM)
Date: Wed Mar 19 2003 - 14:38:03 EST


Cool! Maybe a nice script front-end to awk would do the trick! But I'm
having much too much fun here ... back to work! ;-)

----------------------------------
Bruce T. Harvey (Special Projects)
----------------------------------------
bth@comcast.net -- bruceh@routescape.com
410-236-5721 (cell) -- 410-403-2390 (off.)
-------------------------------------------
Insight Distribution Systems / CoAxis, Inc.
Hunt Valley, Maryland U.S.A. 21031-1422
-------------------------------------------

-----Original Message-----
From: Adams Kevin J [mailto:kevin.adams@PHS.COM]
Sent: Wednesday, March 19, 2003 2:22 PM
To: aix-l@Princeton.EDU
Subject: Re: [aix-l] AW: Scripting: processing stanzas

Bruce,

I hear what you are saying, I was just offering awk up as an option that
would get you up and going quickly as it already understands stanzas
somewhat.

And yes, awk does let you set several characters as record/field separators
within the same file, even as a regex.

Kevin

-----Original Message-----
From: Bruce Harvey [mailto:BruceH@ROUTESCAPE.COM]
Sent: Wednesday, March 19, 2003 10:52 AM
To: aix-l@Princeton.EDU
Subject: Re: [aix-l] AW: Scripting: processing stanzas

Can awk handle a record separator being a blank line consisting of

        ... one or more newlines?
        ... one or more CRs or CRLF pairs?
        ... space, tab, FF or any combination of the above with this?
        ... all within the same file?

That is what _I_ would want, and I think that Simon can easily handle his
own configuration but would prefer a 'general' tool that wouldn't need too
arcane programming or setup. I'd want to see ...

        program -record "label" -value "fred" -return "all" (or
"fullname:address:address1:...") ... and so forth

Leave it to the program to parse what a 'stanza' means within certain
requirements:

May require ':' ending the 'label' line beginning the stanza
following lines may or may not be indented
can specify name/value separator ("=")
...

I currently parse stanzas with fixed types and so forth, but it'd be nice to
have a 'general' parser. I've never found awk(1) to be as flexible as I'd
like it for a full-blown program replacement with various options as above

----------------------------------
Bruce T. Harvey (Special Projects)
----------------------------------------
bth@comcast.net -- bruceh@routescape.com
410-236-5721 (cell) -- 410-403-2390 (off.)
-------------------------------------------
Insight Distribution Systems / CoAxis, Inc.
Hunt Valley, Maryland U.S.A. 21031-1422
-------------------------------------------

-----Original Message-----
From: Adams Kevin J [mailto:kevin.adams@PHS.COM]
Sent: Wednesday, March 19, 2003 1:29 PM
To: aix-l@Princeton.EDU
Subject: Re: [aix-l] AW: Scripting: processing stanzas

Bruce,

I know that Simon said Kornshell, but awk would handle this quite elegantly
by setting the record separator (RS = " ") to a blank line and field
separator to a newline (FS = "\n").

Then you could just parse each field, i.e., "name = fred".

Awk would consider this a basic multiline record.

Kevin Adams

-----Original Message-----
From: Bruce Harvey [mailto:BruceH@ROUTESCAPE.COM]
Sent: Wednesday, March 19, 2003 9:05 AM
To: aix-l@Princeton.EDU
Subject: Re: [aix-l] AW: Scripting: processing stanzas

I know exactly what Simon's talking about, I think.

For example, the info in /etc/passwd is in 'record' format, while
/etc/security/passwd is in "stanza" format. It'd be nice to have a routine
that could parse multi-line entries.

It's easy to parse one like the /etc/passwd file, where the fields are
separated by 'colons' (field1:field2:field3:...), but it's much more of a
pain when your record separator is a line of whitespace, not just a line
ending. Example:

Entry1
        name = fred
        address = 123 Anywhere Lane
        address1 = Bungalow A-2
        city = RightHere
        county = line
        province = rightbigone
        country = mine
        telephone = +012-34-5-67-89

Entry2
        name = irving
        address = (none)
        city = nowhere
        telephone = 0000000000

Entry 3
         ... and so on and so forth.

It would be very nice to have a utility that could:

        1. parse all of the stanzas to obtain all member values
        2. "flatten" the file into one line, if necessary
        3. retrieve a member value (or all) given an entry name
        4. Retrieve all entry name with a given member value
        5. ... etc.

If I were twiddling my thumbs, this is what I'd write and the way I'd write
it. However, I actually have work to do, so is there some overpaid jock
somewhere willing to do this? perl would be desired. ;-)

----------------------------------
Bruce T. Harvey (Special Projects)
----------------------------------------
bth@comcast.net -- bruceh@routescape.com
410-236-5721 (cell) -- 410-403-2390 (off.)
-------------------------------------------
Insight Distribution Systems / CoAxis, Inc.
Hunt Valley, Maryland U.S.A. 21031-1422
-------------------------------------------

-----Original Message-----
From: Holger.VanKoll@SWISSCOM.COM [mailto:Holger.VanKoll@SWISSCOM.COM]
Sent: Wednesday, March 19, 2003 11:50 AM
To: aix-l@Princeton.EDU
Subject: [aix-l] AW: Scripting: processing stanzas

Hello Simon,

I dont understand what you want to do.

Could you give an example?

Regards, Holger

        -----Ursprüngliche Nachricht-----
        Von: Green, Simon [mailto:Simon.Green@EU.ALTRIA.COM]
        Gesendet: Mi 19.03.2003 16:20
        An: aix-l@Princeton.EDU
        Cc:
        Betreff: Scripting: processing stanzas

        Is there any utility analogous to getopt that can be used to process
input
        data in stanza format? Has to be useable with a Korn shell script,
as I
        don't speak Perl or anything clever like that.

        If not, any convenient tricks? I'm writing something from scratch,
so I
        have complete control over the data format but stanzas would be
simple to
        maintain.

        Simon Green
        Altria ITSC Europe s.a.r.l.

        AIX-L Archive at http://marc.theaimsgroup.com/?l=aix-l&r=1&w=2
        AIX FAQ at http://www.faqs.org/faqs/aix-faq/

        N.B. Unsolicited email from vendors will seldom be appreciated.

This electronic message transmission, including any attachments, contains
information from PacifiCare Health Systems Inc. which may be confidential or
privileged. The information is intended to be for the use of the individual
or entity named above. If you are not the intended recipient, be aware that
any disclosure, copying, distribution or use of the contents of this
information is prohibited.

If you have received this electronic transmission in error, please notify
the sender immediately by a "reply to sender only" message and destroy all
electronic and hard copies of the communication, including attachments.

This electronic message transmission, including any attachments, contains
information from PacifiCare Health Systems Inc. which may be confidential or
privileged. The information is intended to be for the use of the individual
or entity named above. If you are not the intended recipient, be aware that
any disclosure, copying, distribution or use of the contents of this
information is prohibited.

If you have received this electronic transmission in error, please notify
the sender immediately by a "reply to sender only" message and destroy all
electronic and hard copies of the communication, including attachments.



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:40 EDT