home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!mcsun!sunic!psinntp!psinntp!dg-rtp!hobbit!hunt
- From: hunt@dg-rtp.rtp.dg.com (Greg Hunt)
- Subject: Re: Awk: Beginner needs help!
- Message-ID: <1992Sep6.194139.15839@dg-rtp.dg.com>
- Sender: hunt@robin (Greg Hunt)
- Date: Sun, 6 Sep 92 19:41:39 GMT
- Distribution: comp.unix.questions
- Reply-To: hunt@dg-rtp.rtp.dg.com
- References: <5608@ucsbcsl.ucsb.edu>
- Organization: Data General Corp., Research Triangle Park, NC
- Keywords: awk unix
- Lines: 68
-
- 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 think this awk script might be easier:
-
- BEGIN {
- getline;
- print "libname saslib '/usr2/username/datasets' ;";
- }
- {if (substr ($1,1,2) != "//") print $0}
-
- Then run it like this for each mvs file you have:
-
- awk -f awk_script mvs_file > unix_file
-
- The BEGIN pattern runs once when the awk script is started. It does
- a getline to read the next line of the input file, thus ignoring the
- first line of the file (the COMMAND? line). Then it prints the line
- that you want instead.
-
- The next pattern runs for each line of the input file. It looks at
- first two bytes of the first field, and if they aren't "//", it prints
- the whole line. This will ignore the JCL statements.
-
- Enjoy!
-
- --
- Greg Hunt email: hunt@dg-rtp.rtp.dg.com
- DG/UX Core Development
- Data General Corporation
- Research Triangle Park, NC, USA These opinions are mine, not DG's.
-