home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / question / 10787 < prev    next >
Encoding:
Text File  |  1992-09-08  |  2.7 KB  |  83 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!mcsun!sunic!psinntp!psinntp!dg-rtp!hobbit!hunt
  3. From: hunt@dg-rtp.rtp.dg.com (Greg Hunt)
  4. Subject: Re: Awk: Beginner needs help!
  5. Message-ID: <1992Sep6.194139.15839@dg-rtp.dg.com>
  6. Sender: hunt@robin (Greg Hunt)
  7. Date: Sun, 6 Sep 92 19:41:39 GMT
  8. Distribution: comp.unix.questions
  9. Reply-To: hunt@dg-rtp.rtp.dg.com
  10. References:  <5608@ucsbcsl.ucsb.edu>
  11. Organization: Data General Corp., Research Triangle Park, NC
  12. Keywords: awk unix
  13. Lines: 68
  14.  
  15. In article <5608@ucsbcsl.ucsb.edu>, 6500scv1@ucsbuxa.ucsb.edu (Steven C. Velasco) writes:
  16. > HI,
  17. > I am new to unix, and really new to awk, so hopefully somebody can
  18. > answer this question real easily.  I have hundreds of SAS program
  19. > files written for MVS, that we now need to run on UNIX.  
  20. > The files from MVS look like this :
  21. > COMMAND? list unnumbered
  22. > //MVS JCL statements
  23. > //MVS JCL statements
  24. > //MVS JCL statements
  25. > DATA _NULL_ ;
  26. >    SET SASLIB.DATASET ;
  27. > MORE SAS STATEMENTS
  28. > RUN ;
  29. > I can get awk to print out the lines that don't contain the string  "//"
  30. > or "COMMAND?" in $1, but I would like to have
  31. > something that replaces the entire line  "COMMAND? list unnumbered"
  32. > (this is always the first line, and occurs just once) 
  33. > with the string: "libname saslib /usr2/username/datasets"  or, to 
  34. > somehow put the "libname" string in the first line of each file.
  35. > So the resulting file would look like this:
  36. > libname saslib '/usr2/username/datasets' ;
  37. > DATA _NULL_ ;
  38. >    SET SASLIB.DATASET ;
  39. > MORE SAS STATEMENTS ;
  40. > RUN ;
  41. > below is my feeble attempt to do this.  When I run this program, I
  42. > get a message saying something like 'awk: cant set $0 at record 1':
  43. > $1 !~ /\/\// { if ( $0 ~ /COMMAND? list unnumbered/ ) 
  44. > $0 = "libname saslib /usr2/username/datasets ;" 
  45. > print >FILENAME }  
  46. > What am I doing wrong?  I would appreciate any help or suggestions.
  47.  
  48. I think this awk script might be easier:
  49.  
  50.     BEGIN {
  51.         getline;
  52.         print "libname saslib '/usr2/username/datasets' ;";
  53.           }
  54.     {if (substr ($1,1,2) != "//") print $0}
  55.  
  56. Then run it like this for each mvs file you have:
  57.  
  58.     awk -f awk_script mvs_file > unix_file
  59.  
  60. The BEGIN pattern runs once when the awk script is started.  It does
  61. a getline to read the next line of the input file, thus ignoring the
  62. first line of the file (the COMMAND? line).  Then it prints the line
  63. that you want instead.
  64.  
  65. The next pattern runs for each line of the input file.  It looks at
  66. first two bytes of the first field, and if they aren't "//", it prints
  67. the whole line.  This will ignore the JCL statements.
  68.  
  69. Enjoy!
  70.  
  71. -- 
  72. Greg Hunt                            email: hunt@dg-rtp.rtp.dg.com
  73. DG/UX Core Development
  74. Data General Corporation
  75. Research Triangle Park, NC, USA      These opinions are mine, not DG's.
  76.