Date: Sun, 17 Mar 2002 20:33:04 -0600 (CST) From: hawkeyd@visi.com (D J Hawkey Jr) To: parv_@yahoo.com, freebsd-questions@freebsd.org Subject: Re: awk - any possibility of using a variable in regex Message-ID: <200203180233.g2I2X4n22005@sheol.localdomain> In-Reply-To: <20020317223910.GA3245_moo.holy.cow@ns.sol.net> References: <20020317223910.GA3245_moo.holy.cow@ns.sol.net>
next in thread | previous in thread | raw e-mail | index | archive | help
In article <20020317223910.GA3245_moo.holy.cow@ns.sol.net>, parv_@yahoo.com writes: > is it impossible to use a variable inside a regex in awk? i tried > the following w/o any success... > > { echo 'polka dot'; echo 'red dot'; } | \ > awk -v type=polka ' BEGIN { dot_type=type } /dot_type/ { print }' > > ...so i had resorted to perl for now. > > actual usage is to kill X applications -- xinit, startx -- (from > /usr/share/skel/dot.xinitrc)... > > [SNIP] Hey, I could use something like this! I don't know if awk REs support variables - I played with your example some, and it doesn't do anything for me - but I can make your script a little more efficient by eliminating the perl. Try something like this: ---8<--- #!/bin/sh TMP=/var/tmp/$0.$$ teststop () { [ `ps -aO ruser |egrep $LOGNAME.+$1 | grep -v grep | tee $TMP | wc -l` -eq 1 ] && kill -9 `cat $TMP | awk '{ print $1 }'` rm -f $TMP } teststop startx teststop xinit --->8--- A little more time and creativity could pro'lly eliminate the temporary file, and maybe the awk, too. > - parv Hope this helps, Dave -- Windows: "Where do you want to go today?" Linux: "Where do you want to go tomorrow?" FreeBSD: "Are you guys coming, or what?" To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203180233.g2I2X4n22005>