home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10745 < prev    next >
Encoding:
Internet Message Format  |  1992-09-07  |  2.5 KB

  1. Path: sparky!uunet!convex!darwin.sura.net!news.larc.nasa.gov!uakari.primate.wisc.edu!ames!stanford.edu!rutgers!att-out!walter!fork!snk
  2. From: snk@fork.bae.bellcore.com (Samuel Kamens)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Awk: Beginner needs help!
  5. Keywords: awk unix
  6. Message-ID: <1992Sep4.202238.27202@walter.bellcore.com>
  7. Date: 4 Sep 92 20:22:38 GMT
  8. References: <5608@ucsbcsl.ucsb.edu>
  9. Sender: news@walter.bellcore.com
  10. Reply-To: snk@bae.bellcore.com
  11. Distribution: comp.unix.questions
  12. Organization: Bell Communications Research
  13. Lines: 68
  14. Nntp-Posting-Host: fork.bae.bellcore.com
  15.  
  16. In article <5608@ucsbcsl.ucsb.edu>, 6500scv1@ucsbuxa.ucsb.edu (Steven C. Velasco) writes:
  17. > HI,
  18. > I am new to unix, and really new to awk, so hopefully somebody can
  19. > answer this question real easily.  I have hundreds of SAS program
  20. > files written for MVS, that we now need to run on UNIX.  
  21. > The files from MVS look like this :
  22. > COMMAND? list unnumbered
  23. > //MVS JCL statements
  24. > //MVS JCL statements
  25. > //MVS JCL statements
  26. > DATA _NULL_ ;
  27. >    SET SASLIB.DATASET ;
  28. > MORE SAS STATEMENTS
  29. > RUN ;
  30. > I can get awk to print out the lines that don't contain the string  "//"
  31. > or "COMMAND?" in $1, but I would like to have
  32. > something that replaces the entire line  "COMMAND? list unnumbered"
  33. > (this is always the first line, and occurs just once) 
  34. > with the string: "libname saslib /usr2/username/datasets"  or, to 
  35. > somehow put the "libname" string in the first line of each file.
  36. > So the resulting file would look like this:
  37. > libname saslib '/usr2/username/datasets' ;
  38. > DATA _NULL_ ;
  39. >    SET SASLIB.DATASET ;
  40. > MORE SAS STATEMENTS ;
  41. > RUN ;
  42. > below is my feeble attempt to do this.  When I run this program, I
  43. > get a message saying something like 'awk: cant set $0 at record 1':
  44. > $1 !~ /\/\// { if ( $0 ~ /COMMAND? list unnumbered/ ) 
  45. > $0 = "libname saslib /usr2/username/datasets ;" 
  46. > print >FILENAME }  
  47. > What am I doing wrong?  I would appreciate any help or suggestions.
  48.  
  49. I think what you're doing wrong is using the wrong tool!
  50.  
  51. Try it with sed, as follows:
  52.  
  53. sed \
  54. -e "s:COMMAND? list unnumbered:libname saslib'/usr2/username/datasets';:" \
  55. -e /^COMMAND/d \
  56. -e /^\/\//d \
  57. filename > outfile.
  58.  
  59.  
  60. You could also do it in awk, as follows:
  61.  
  62. awk '/^COMMAND?/     { print "libname saslib '/usr2/username/datasets' ;"
  63.               next
  64.               }
  65.      /^\/\//            { next }
  66.             { print }
  67. ' infile
  68.  
  69.  
  70.  
  71. See which one you like better!!
  72.  
  73. Sam Kamens                    Bell Communications Research
  74. snk@bae.bellcore.com                Phone: (908) 699-7509
  75. 444 Hoes Lane  Room RRC 1D-210
  76. Piscataway, NJ 08854
  77.