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

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!milano!cactus.org!cheselka
  3. From: cheselka@cactus.org (Michael R. M. Cheselka)
  4. Subject: two simple nawk questions, Sunos 4.1.2 and nawk
  5. Message-ID: <1992Aug24.023958.17325@cactus.org>
  6. Summary: printing out ranges like $1-$19, and parameterless nawk scripts
  7. Organization: Capital Area Central Texas UNIX Society, Austin, Tx
  8. Date: Mon, 24 Aug 1992 02:39:58 GMT
  9. Lines: 46
  10.  
  11. I am trying to nawk through a file and change in the 20th field the value
  12. of the date from mo/da/year, as in 02/30/1993, to mo/ld/year, as in
  13. 02/28/1993( where da is any particular day, even wrong ones, and ld is the
  14. correct last day of the month), and the two problems I can't solve are,
  15. that I can't get the shell wrapper to work like I would like without having
  16. to specify a file on the command line, and I am having trouble finding a
  17. way to print out the line when I am done, using ranges, like $1-$19.
  18.  
  19. I would like to do:
  20.  
  21. 1)
  22. #! /bin/nawk -f # Call the nawk script without any parameters
  23. BEGIN { FS = "|";
  24.        OFS = "|" }
  25. { while ( getline <"Data.file" > 0 )
  26.  
  27. ...rest of script...
  28.  
  29. How can I run this program without having to use:
  30.  
  31. mysys: ~ $ datefix Data.file
  32.  
  33. In otherwords, just by typing the script name( without Data.file).
  34.  
  35. 2)
  36. How do I specify a range for a print statement:
  37.  
  38. print $1-$19,date,$21-$37
  39.  
  40. Right now it seems I have to have a line like:
  41.  
  42. print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14...goes on and on till
  43. I wanna scream!
  44.  
  45. I am sorry if these are obvious questions or FAQ's, but nothing about them
  46. appears in the O'Rielly book, or anywhere else.  I guess the creaters of
  47. nawk expect you to write filters like:
  48.  
  49. mysys: ~ $ datefix -F\| -f20 < Data.file > Data.file.fixed
  50.  
  51. but I want to do it my way.
  52. -- 
  53. cheselka@cactus.org               N5UVV              Michael R. M. Cheselka
  54. os9@gnu.ai.mit.edu        Hangs out on 145.21mhz       400 W. 34th st. #103
  55. membership@cactus.org                                 Austin, TX 78705-1331
  56. {...}!cs.utexas!cactus.org!cheselka (512)452-9412v ( 24hours answer. mach.)
  57.