Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Mar 2002 03:18:48 -0500
From:      parv <parv_@yahoo.com>
To:        D J Hawkey Jr <hawkeyd@visi.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: awk - any possibility of using a variable in regex
Message-ID:  <20020318081848.GA4720@moo.holy.cow>
In-Reply-To: <20020318075440.GA3810@moo.holy.cow>
References:  <20020317205228.A22100@sheol.localdomain> <20020318075440.GA3810@moo.holy.cow>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020318081848.GA4720>