home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!convex!darwin.sura.net!news.larc.nasa.gov!uakari.primate.wisc.edu!ames!stanford.edu!rutgers!att-out!walter!fork!snk
- From: snk@fork.bae.bellcore.com (Samuel Kamens)
- Newsgroups: comp.unix.questions
- Subject: Re: Awk: Beginner needs help!
- Keywords: awk unix
- Message-ID: <1992Sep4.202238.27202@walter.bellcore.com>
- Date: 4 Sep 92 20:22:38 GMT
- References: <5608@ucsbcsl.ucsb.edu>
- Sender: news@walter.bellcore.com
- Reply-To: snk@bae.bellcore.com
- Distribution: comp.unix.questions
- Organization: Bell Communications Research
- Lines: 68
- Nntp-Posting-Host: fork.bae.bellcore.com
-
- 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 what you're doing wrong is using the wrong tool!
-
- Try it with sed, as follows:
-
- sed \
- -e "s:COMMAND? list unnumbered:libname saslib'/usr2/username/datasets';:" \
- -e /^COMMAND/d \
- -e /^\/\//d \
- filename > outfile.
-
-
- You could also do it in awk, as follows:
-
- awk '/^COMMAND?/ { print "libname saslib '/usr2/username/datasets' ;"
- next
- }
- /^\/\// { next }
- { print }
- ' infile
-
-
-
- See which one you like better!!
-
- Sam Kamens Bell Communications Research
- snk@bae.bellcore.com Phone: (908) 699-7509
- 444 Hoes Lane Room RRC 1D-210
- Piscataway, NJ 08854
-