home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!mcsun!Germany.EU.net!murignis!ap542!D012S436!frank
- From: frank@D012S436.sniap.mchp.sni.de ()
- Subject: Re: More fun with awk! (not associative arrays, I promise. ;-)
- Message-ID: <1992Aug26.143712.8667@sniap.mchp.sni.de>
- Sender: news@sniap.mchp.sni.de (News Admin)
- Organization: Siemens-Nixdorf AG
- References: <1992Aug24.193819.26442@news.acns.nwu.edu>
- Date: Wed, 26 Aug 92 14:37:12 GMT
- Lines: 42
-
- navarra@casbah.acns.nwu.edu (John Navarra) writes:
- : Well, here is my newest awk problem I haven't figured out.
- : I have the following text that I want to play with:
- :
- : ...
- : [2] Canada North America
- : [3] China Asia
- : [4] Argentina South America
- : ...
- : [6] United States North America
- : [7] Scotland Europe
- : [8] Australia Australia
- : [9] Chad Africa
- : [10] Brazil South America
- :
- : This is generated from a program I wrote to extract the blocks of
- : text between two patterns (in this case, between North and South).
- : The numbers to the left are the line numbers in the file. If text
- : is skipped, I print out a '...'.
- :
- : What I would like to do now, is write a simple awk filter to grab the
- : first and last block of text (where blocks are separated by a "...".)
- : In this case, the first block of text is lines 2-4 and the last is
- : lines 6-10. The book I have describes multi-line records in awk
- : but this does not do what I want. I seem to need a multi-line field.
- : If I could set the FS to "..." and print $1, $2 .. $NF this would be
- : great. Unfortunately, I don't think this is the case.
- :
- : From what I read, the normal way to handle multi-line records is to
- : set FS="\n" and RS="...". Then $1 is line [2], $2 is line [3] etc.
- : However, there are a variable number of lines in the block and
-
- You could print $1..$NF in a loop...
-
- e.g. for(i=1; i<=NF;i++)
- print $i
-
- --
- Frank O'Dwyer Disclaimer:
- Siemens-Nixdorf AG I will deny everything
- Tel. : +49 (89) 636-40639 Fax. : +49 (89) 636-45860
- e-mail: Frank.ODwyer@sniap.mchp.sni.de
-