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 8 of 20 Topic 2187 of 2236
Post > Topic >>

Re: using a variable to help define a regular expression

by Steffen Schuler <schuler.steffen@[EMAIL PROTECTED] > Mar 13, 2008 at 08:40 AM

On Thu, 13 Mar 2008 07:49:28 +0000, tbh wrote:

> <schuler.steffen@[EMAIL PROTECTED]
> wrote in message
> news:f47cefc3-0878-4476-8d0a-
e81678a8e50f@[EMAIL PROTECTED]
>> Faster than using a dynamic string as a regex is to use a regex
>> constant (e.g. /.../).
> 
> thanks. is that possible though, when i need to put a variable part in
> the middle of my regex (constant for each run, but variable in general)?
> 
>> E.g.:
>> 
>> unpackHourlyWebLogs.bash  11 |
>> {
>>   base=f30
>>   gawk 'tolower($5) ~ /^\/'"$base"'\// {
                         ^^^^^^^^^^^^^^^^
this is the use of a regex constant with embedded shell variable

>>           print $3, $5, $6
>>           if (++i == 10) exit
             ^^^^^^^^^^^^^^^^^^^
this line does the head; you can remove it

>>         }'
>> }

>> And still faster than your pipe from gawk to head is to let gawk do the
>> head cmd.
> 
> thanks, good to remember. head is not part of the actual assignment here
> -- just there to reduce the data storm for the test.
> 
> cheers,
> 
> Tim





-- 
Steffen




 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 8:06:43 CDT 2008.