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 2 of 20 Topic 2187 of 2241
Post > Topic >>

Re: using a variable to help define a regular expression

by Janis Papanagnou <Janis_Papanagnou@[EMAIL PROTECTED] > Mar 12, 2008 at 07:09 PM

tbh wrote:
> hi, i'm not a complete awk beginnger, but also no expert.
> 
> I'm trying to do something reasonably simple and am having trouble. i
can do 
> the same thing in perl, but my case (reading pretty massive input under 
> cygwin under windows) that degrades performance.
> 
> I'd like to use a variable as part of a regular expression as follows:
>      $ unpackHourlyWebLogs.bash  11 | gawk '(tolower($5) ~
("^/"+base+"/")) 
> {print $3,$5,$6}' base="f30" | head
>      SVWEB01 /f30/Images/diverse/bg_htab1.gif -
>      SVWEB01 /f30/Images/wetter/Gewitter.gif -
>      SVWEB01 /m/{EE71E7A4-8115-4F21-AED0-328011C2079C}Picture.GIF -
>      ...
> 
> unfortunately my output includes matches and non-matches ($5 should
begin 
> /f30/ in this example, but the 3rd hit begins /m/. i also tried
initializing 
> the pattern matching string in the BEGIN clause (which might also help 
> performance?), but that didn't help.
> 
> maybe a seasoned (g)awker can spot my mistake?

The biggest problem is that string concatenation is *not* the '+',
instead construct a string like this...

   "^/" base "/"


Janis

> 
> i'd be grateful.
> 
> Tim Hanson
> 
> p.s. i meant to simplify the example considerably, but this time i
matched 
> nothing, e.g.:
>     echo "/a/|/b/" | tr '|' '\n' | gawk 'BEGIN {pat=("^[/]" + base + 
> "[/]");} (tolower($5) ~ pat) {print $3,$5}' base="a"
> 
>




 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 Sat May 17 4:05:04 CDT 2008.