From owner-freebsd-questions Mon Mar 18 0:16:44 2002 Delivered-To: freebsd-questions@freebsd.org Received: from albatross.prod.itd.earthlink.net (albatross.mail.pas.earthlink.net [207.217.120.120]) by hub.freebsd.org (Postfix) with ESMTP id 0B01937B400 for ; Mon, 18 Mar 2002 00:16:36 -0800 (PST) Received: from sdn-ar-007dcwashp005.dialsprint.net ([63.178.91.13] helo=moo.holy.cow) by albatross.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16msJj-0003BH-00; Mon, 18 Mar 2002 00:16:31 -0800 Received: by moo.holy.cow (Postfix, from userid 1001) id 5AEAA50B8B; Mon, 18 Mar 2002 03:18:48 -0500 (EST) Date: Mon, 18 Mar 2002 03:18:48 -0500 From: parv To: D J Hawkey Jr Cc: freebsd-questions@freebsd.org Subject: Re: awk - any possibility of using a variable in regex Message-ID: <20020318081848.GA4720@moo.holy.cow> Mail-Followup-To: D J Hawkey Jr , freebsd-questions@freebsd.org References: <20020317205228.A22100@sheol.localdomain> <20020318075440.GA3810@moo.holy.cow> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020318075440.GA3810@moo.holy.cow> 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 message <20020318075440.GA3810@moo.holy.cow>, wrote parv thusly... > > i was so intent on using awk to avoid two greps like above that i > missed the fact that i could have used variables w/ grep. ... > for proc in startx xinit # etc... > do > pids=$(ps -a -O ruser -c | egrep "${user}.+\<${proc}\>" | awk '!/grep/{ print $1 }') ... well for the sake of argument it's possible to eliminate the need of grep, but that comes at the cost of readability/maintainability. just remember to keep the quotes balanced... pids=$(ps -a -O ruser -c | awk '!/awk/ && /'"${user}"'.+\<'"${proc}"'\>/ {print $1}') -- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message