Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!vsi1!wyse!bob From: bob@wyse.wyse.com (Bob McGowen x4312 dept208) Newsgroups: comp.unix.shell Subject: Re: Awk question Message-ID: <3094@wyse.wyse.com> Date: 19 Jan 91 17:41:58 GMT References: <1991Jan18.164243.11804@cbnewsh.att.com> Sender: news@wyse.wyse.com Reply-To: bob@wyse.UUCP (Bob McGowen x4312 dept208) Distribution: usa Organization: Wyse Technology Lines: 55 In article <1991Jan18.164243.11804@cbnewsh.att.com> me@cbnewsh.att.com (william.j.bruncati) writes: >I am having a problem with an awk program. >What I'm trying to do is have an array element >match on a pattern in the first field. >I can match on the fixed string >but not the pattern. Can anyone help? > >This works. > if (myarray[i] == $1 ) > print $0 > >This doesn't work. It won't give me a match although there is one. > if (myarray[i] ~ /$1/ ) > print $0 I believe this is because you are using "old" awk, which did not allow substitution into patterns, as with your "/$1/". Check to see if you have executables named "oawk" and "nawk". If so, "oawk" will most likely be linked to "awk", so you will want to change the command to "nawk". >Also, while I'm posting, could someone tell me if it's possible >to have nested case statements in shell? Yes, assuming you use sh.I do not know about csh. I have on occasion used the following to step through all arguments looking for options and then checking the options to see if they are legal ones: for arg in $* # assume no args will have white space do case $arg in -*) # this is an option case $arg in -h) ;; -p) ;; -x) ;; -*) ;; esac *) # this is not an option item="$item $arg" esac done > Thanks in advance, > Bill Bruncati I hope this is useful. Bob McGowan (standard disclaimer, these are my own ...) Product Support, Wyse Technology, San Jose, CA ..!uunet!wyse!bob bob@wyse.com