home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10398 < prev    next >
Encoding:
Text File  |  1992-08-26  |  2.1 KB  |  54 lines

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