Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: using a var...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 17 of 20 Topic 2187 of 2236
Post > Topic >>

Re: using a variable to help define a regular expression

by Janis <janis_papanagnou@[EMAIL PROTECTED] > Mar 14, 2008 at 02:09 AM

On 14 Mrz., 08:49, "tbh" <fem...@[EMAIL PROTECTED]
> wrote:
> thanks, Ed,
>
> > Someone had suggested you do something like this:
>
> > base=3D"f30"
> > unpackHourlyWebLogs.bash =A011 | gawk 'tolower($5) ~ "^/'"$base"'/"
{pri=
nt
> > $3,$5,$6} NR=3D=3D10{exit}'
>
> > to use a shell variable in the middle of your awk script. Don't do
that =
as
> > it
> > can lead to hard-to-diagnose failures, e.g.:
>
> as it happens i still haven't managed to get that variation going, so
i've=

> given up for now. i have only 3 cases for "base" in my current data
> collection, so it's simple enough to run three commands. this even has
som=
e
> other advantages relating to how i'll use the data.
>
> i guess it's instructive to me that this appears non-trivial (and even a
b=
it
> controversial?) in a language as mature as awk.

No, it is trivial. Any "non-triviality" here stems from shell
quoting issues and from mixing shell level and awk level code.
I also think it hasn't been controversial (at least comparing
suggestions amongst posters of a similar experience).

(Some non-trivialities will appear if your dynamic regexps
contains regexp meta-characters.)

(BTW, since it hasn't been mentioned yet; to avoid problems
with quoting you can put the awk program in a file and call
it using awk's -f option. As a side effect you are forced to
use a cleaner and more robust way to pass shell variables.)

Janis

>
> cheers,
>
> Tim




 20 Posts in Topic:
using a variable to help define a regular expression
"tbh" <femde  2008-03-12 17:38:20 
Re: using a variable to help define a regular expression
Janis Papanagnou <Jani  2008-03-12 19:09:56 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-13 07:46:23 
Re: using a variable to help define a regular expression
schuler.steffen@[EMAIL PR  2008-03-12 16:13:49 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-13 07:49:28 
Re: using a variable to help define a regular expression
Lorenz <lorenznl@[EMAI  2008-03-13 07:02:29 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-13 07:50:13 
Re: using a variable to help define a regular expression
Steffen Schuler <schul  2008-03-13 08:40:12 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-13 12:12:53 
Re: using a variable to help define a regular expression
Lorenz <lorenznl@[EMAI  2008-03-13 12:35:05 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-13 15:00:37 
Re: using a variable to help define a regular expression
Janis <janis_papanagno  2008-03-13 01:41:08 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-13 09:06:18 
Re: using a variable to help define a regular expression
Ed Morton <morton@[EMA  2008-03-13 17:37:55 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-14 07:49:49 
Re: using a variable to help define a regular expression
Ed Morton <morton@[EMA  2008-03-14 07:15:02 
Re: using a variable to help define a regular expression
Janis <janis_papanagno  2008-03-14 02:09:22 
Re: using a variable to help define a regular expression
"tbh" <femde  2008-03-14 12:15:19 
Re: using a variable to help define a regular expression
Ed Morton <morton@[EMA  2008-03-14 07:50:03 
Re: using a variable to help define a regular expression
mjc <mjcohen@[EMAIL PR  2008-03-15 13:23:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 7:18:38 CDT 2008.