Re: AW: Scripting: processing stanzas

From: Adams Kevin J (kevin.adams@PHS.COM)
Date: Wed Mar 19 2003 - 13:28:38 EST


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 archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:40 EDT