home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10723 < prev    next >
Encoding:
Text File  |  1992-09-03  |  2.4 KB  |  81 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!mcsun!sunic!ericom!eos.ericsson.se!etxmesa
  3. From: etxmesa@eos.ericsson.se (Michael Salmon)
  4. Subject: Re: Awk: Beginner needs help!
  5. Message-ID: <1992Sep4.073213.4037@ericsson.se>
  6. Keywords: awk unix
  7. Sender: news@ericsson.se
  8. Nntp-Posting-Host: eos6c02.ericsson.se
  9. Reply-To: etxmesa@eos.ericsson.se (Michael Salmon)
  10. Organization: Ericsson Telecom AB
  11. References:  <5608@ucsbcsl.ucsb.edu>
  12. Distribution: comp.unix.questions
  13. Date: Fri, 4 Sep 1992 07:32:13 GMT
  14. Lines: 65
  15.  
  16. In article <5608@ucsbcsl.ucsb.edu>, 
  17. 6500scv1@ucsbuxa.ucsb.edu (Steven C. Velasco) writes:
  18. |> 
  19. |> HI,
  20. |> I am new to unix, and really new to awk, so hopefully somebody can
  21. |> answer this question real easily.  I have hundreds of SAS program
  22. |> files written for MVS, that we now need to run on UNIX.  
  23. |> The files from MVS look like this :
  24. |> 
  25. |> COMMAND? list unnumbered
  26. |> //MVS JCL statements
  27. |> //MVS JCL statements
  28. |> //MVS JCL statements
  29. |> DATA _NULL_ ;
  30. |>    SET SASLIB.DATASET ;
  31. |> MORE SAS STATEMENTS
  32. |> RUN ;
  33. |> 
  34. |> I can get awk to print out the lines that don't contain the string  "//"
  35. |> or "COMMAND?" in $1, but I would like to have
  36. |> something that replaces the entire line  "COMMAND? list unnumbered"
  37. |> (this is always the first line, and occurs just once) 
  38. |> with the string: "libname saslib /usr2/username/datasets"  or, to 
  39. |> somehow put the "libname" string in the first line of each file.
  40. |> So the resulting file would look like this:
  41. |> 
  42. |> libname saslib '/usr2/username/datasets' ;
  43. |> DATA _NULL_ ;
  44. |>    SET SASLIB.DATASET ;
  45. |> MORE SAS STATEMENTS ;
  46. |> RUN ;
  47. |> 
  48. |> below is my feeble attempt to do this.  When I run this program, I
  49. |> get a message saying something like 'awk: cant set $0 at record 1':
  50. |> 
  51. |> $1 !~ /\/\// { if ( $0 ~ /COMMAND? list unnumbered/ ) 
  52. |> $0 = "libname saslib /usr2/username/datasets ;" 
  53. |> print >FILENAME }  
  54. |> 
  55. |> What am I doing wrong?  I would appreciate any help or suggestions.
  56.  
  57. I would solve this in this way:
  58.  
  59. #!/usr/bin/awk
  60. BEGIN { print "libname saslib /usr2/username/datasets ;" }
  61.  
  62. /^\/\// { next }
  63. /^COMMAND?/ { next }
  64. { print }
  65.  
  66. The first line is only useful if you system supports this. I would also
  67. guess that the COMMAND? line could be used for something useful but I
  68. don't know anything about SAS other than that it is Sweden's
  69. international airline ;^)
  70.  
  71. -- 
  72.  
  73. Michael Salmon
  74.  
  75. #include    <standard.disclaimer>
  76. #include    <witty.saying>
  77. #include    <fancy.pseudo.graphics>
  78.  
  79. Ericsson Telecom AB
  80. Stockholm
  81.