Awk question
Bob McGowen x4312 dept208
bob at wyse.wyse.com
Sun Jan 20 04:41:58 AEST 1991
In article <1991Jan18.164243.11804 at cbnewsh.att.com> me at 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 at wyse.com
More information about the Comp.unix.shell
mailing list