From owner-freebsd-questions Sun Mar 17 14:37: 3 2002 Delivered-To: freebsd-questions@freebsd.org Received: from gull.prod.itd.earthlink.net (gull.mail.pas.earthlink.net [207.217.120.84]) by hub.freebsd.org (Postfix) with ESMTP id 4CBA237B400 for ; Sun, 17 Mar 2002 14:36:54 -0800 (PST) Received: from sdn-ar-007dcwashp211.dialsprint.net ([63.178.91.123] helo=moo.holy.cow) by gull.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16mjGn-00065a-00 for freebsd-questions@freebsd.org; Sun, 17 Mar 2002 14:36:53 -0800 Received: by moo.holy.cow (Postfix, from userid 1001) id DDF9050B8B; Sun, 17 Mar 2002 17:39:10 -0500 (EST) Date: Sun, 17 Mar 2002 17:39:10 -0500 From: parv To: f-q Subject: awk - any possibility of using a variable in regex Message-ID: <20020317223910.GA3245@moo.holy.cow> Mail-Followup-To: f-q Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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)... ... if [ -x /usr/X11R6/bin/fvwm2 ] then # ... elif [ -x /usr/X11R6/bin/twm ] then # ... else echo ' neither fvwm2 nor twm is available/executable; exiting...' echo ' cleaning up...' /bin/ps wwaux | \ /usr/local/bin/perl -n -e \ '$usr = $ENV{$USER} ? $ENV{USER} : $ENV{LOGNAME}; if ( m#^$usr.+\b(?:startx|xinit)\b#o ) { (undef, $pid) = split(/[ ]+/); print "$pid\n" if ($pid =~ /^\d+$/); } ' | \ /usr/bin/xargs /bin/kill -9 echo ' ...done' exit 1 fi - parv -- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message