awk & variables

Jean-Pierre Radley jpr at dasys1.UUCP
Wed Jun 7 07:09:03 AEST 1989


In article <23206 at dhw68k.cts.com>, jaff at dhw68k.cts.com (Mark Jaffe) writes:
> Awk seems to be lacking something, but maybe it's really there.  I want to
> match a pattern that I don't know until I execute the script, so I want to
> pass in a pattern to match in a variable.  I can't get this to work!  Here's
> what I'm doing, on a Sun:
> SYSVER=`awk '{print $3}' < /etc/motd`
> awk ' $0 ~ $SYSVER { print substr($0, 3, length - 2) } ' < cs35if.h > cs35.if 

If you wanted to really get into hairy quotation mechanisms, you could
even extract your /etc/motd info from within awk. But this should work for
you:

SYSVER=`awk '{print $3}' < /etc/motd`
awk "
/"$SYSVER"/ { print substr($0, 3, length - 2) }
" < cs35if.h > cs35.if 

BTW, I think it faster to change your first line to:
set `/etc/motd` ; SYSVER=$3
-- 
Jean-Pierre Radley		CIS: 72160,1341		jpr at jpradley.UUCP



More information about the Comp.unix.wizards mailing list