From: Ford, Phillip (phillip.ford@SPCORP.COM)
Date: Wed Mar 19 2003 - 13:45:16 EST
In the O'reilly book "sed & awk" there is an example of working in awk with
multiline records (i.e. stanzas). If you had the following file
John smith
SP corp
Boston
MA 12345
696-0022
Jane doe
Ddd corp
New york
NY 23456
334-1234
If you do the following in awk
BEGIN ( FS = "\n"; RS = "" )
(print $1 , $NF )
This says to make the field separator the line feed and the record separator
a blank line and would print the following:
John smith 696-0022
Jane doe 334-1234
If you wanted the output to be stanzas then add OFS = "\n", ORS = "\n\n" to
the begin block and you would get
John smith
696-0022
Jane doe
334-1234
If nothing else you could use awk to reformat it out of stanza mode to work
with and then another awk to put it back into stanza mode. Awk can call
other scripts and pass its fields to the other script for processing. The
book is really great and should be in everyone's book case.
Hope that helps some
-- Phillip Ford Senior Software Specialist Corporate Computer Center Schering-Plough Corp. (901) 320-4462 (901) 320-4856 FAX phillip.ford@spcorp.com -----Original Message----- From: Bruce Harvey [mailto:BruceH@ROUTESCAPE.COM] Sent: Wednesday, March 19, 2003 11:05 AM To: aix-l@Princeton.EDU Subject: Re: 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 message and any attachments are solely for the intended recipient. If you are not the intended recipient, disclosure, copying, use or distribution of the information included in this message is prohibited -- Please immediately and permanently delete.
This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:40 EDT