From owner-freebsd-questions Sun Mar 17 18:33:29 2002 Delivered-To: freebsd-questions@freebsd.org Received: from breg.mc.mpls.visi.com (breg.mc.mpls.visi.com [208.42.156.101]) by hub.freebsd.org (Postfix) with ESMTP id EC50E37B402 for ; Sun, 17 Mar 2002 18:33:06 -0800 (PST) Received: from sheol.localdomain (hawkeyd-fw.dsl.visi.com [208.42.101.193]) by breg.mc.mpls.visi.com (Postfix) with ESMTP id 02F8C2D04A6; Sun, 17 Mar 2002 20:33:06 -0600 (CST) Received: (from hawkeyd@localhost) by sheol.localdomain (8.11.6/8.11.6) id g2I2X4n22005; Sun, 17 Mar 2002 20:33:04 -0600 (CST) (envelope-from hawkeyd) Date: Sun, 17 Mar 2002 20:33:04 -0600 (CST) Message-Id: <200203180233.g2I2X4n22005@sheol.localdomain> Mime-Version: 1.0 X-Newsreader: knews 1.0b.1 Reply-To: hawkeyd@visi.com Organization: if (!FIFO) if (!LIFO) break; References: <20020317223910.GA3245_moo.holy.cow@ns.sol.net> In-Reply-To: <20020317223910.GA3245_moo.holy.cow@ns.sol.net> From: hawkeyd@visi.com (D J Hawkey Jr) Subject: Re: awk - any possibility of using a variable in regex X-Original-Newsgroups: sol.lists.freebsd.questions To: parv_@yahoo.com, freebsd-questions@freebsd.org Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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