home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!mcsun!sunic!ericom!eos.ericsson.se!etxmesa
- From: etxmesa@eos.ericsson.se (Michael Salmon)
- Subject: Re: Awk: Beginner needs help!
- Message-ID: <1992Sep4.073213.4037@ericsson.se>
- Keywords: awk unix
- Sender: news@ericsson.se
- Nntp-Posting-Host: eos6c02.ericsson.se
- Reply-To: etxmesa@eos.ericsson.se (Michael Salmon)
- Organization: Ericsson Telecom AB
- References: <5608@ucsbcsl.ucsb.edu>
- Distribution: comp.unix.questions
- Date: Fri, 4 Sep 1992 07:32:13 GMT
- Lines: 65
-
- In article <5608@ucsbcsl.ucsb.edu>,
- 6500scv1@ucsbuxa.ucsb.edu (Steven C. Velasco) writes:
- |>
- |> HI,
- |> I am new to unix, and really new to awk, so hopefully somebody can
- |> answer this question real easily. I have hundreds of SAS program
- |> files written for MVS, that we now need to run on UNIX.
- |> The files from MVS look like this :
- |>
- |> COMMAND? list unnumbered
- |> //MVS JCL statements
- |> //MVS JCL statements
- |> //MVS JCL statements
- |> DATA _NULL_ ;
- |> SET SASLIB.DATASET ;
- |> MORE SAS STATEMENTS
- |> RUN ;
- |>
- |> I can get awk to print out the lines that don't contain the string "//"
- |> or "COMMAND?" in $1, but I would like to have
- |> something that replaces the entire line "COMMAND? list unnumbered"
- |> (this is always the first line, and occurs just once)
- |> with the string: "libname saslib /usr2/username/datasets" or, to
- |> somehow put the "libname" string in the first line of each file.
- |> So the resulting file would look like this:
- |>
- |> libname saslib '/usr2/username/datasets' ;
- |> DATA _NULL_ ;
- |> SET SASLIB.DATASET ;
- |> MORE SAS STATEMENTS ;
- |> RUN ;
- |>
- |> below is my feeble attempt to do this. When I run this program, I
- |> get a message saying something like 'awk: cant set $0 at record 1':
- |>
- |> $1 !~ /\/\// { if ( $0 ~ /COMMAND? list unnumbered/ )
- |> $0 = "libname saslib /usr2/username/datasets ;"
- |> print >FILENAME }
- |>
- |> What am I doing wrong? I would appreciate any help or suggestions.
-
- I would solve this in this way:
-
- #!/usr/bin/awk
- BEGIN { print "libname saslib /usr2/username/datasets ;" }
-
- /^\/\// { next }
- /^COMMAND?/ { next }
- { print }
-
- The first line is only useful if you system supports this. I would also
- guess that the COMMAND? line could be used for something useful but I
- don't know anything about SAS other than that it is Sweden's
- international airline ;^)
-
- --
-
- Michael Salmon
-
- #include <standard.disclaimer>
- #include <witty.saying>
- #include <fancy.pseudo.graphics>
-
- Ericsson Telecom AB
- Stockholm
-