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

Re: using a variable to help define a regular expression

by mjc <mjcohen@[EMAIL PROTECTED] > Mar 15, 2008 at 01:23 PM

On Mar 14, 8:15 am, "tbh" <fem...@[EMAIL PROTECTED]
> wrote:
> "Janis" wrote in message
>
> news:18784f90-e0de-450c-8c93-a91d5dee36d4@[EMAIL PROTECTED]
>
> > > i guess it's instructive to me that this appears non-trivial (and
even a
> > > bit
> > > 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.)
>
> thanks, that was perhaps careless of me. maybe we could agree on
"trivial"
> in theory, sometimes non-trivial (or non-portable? or potentially
> troublesome in some cases?) in practice.
>
> speaking of which, i now got this to work in cygwin and under linux
>
>     echo "/a/|/b/" | tr '|' '\n' | awk -v base="a" '($1 ~ "/"base"/")
> {print}'
>
> so I'm a happy camper.
>
> > (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.)
>
> good to know, thanks. i have occasionally used awk that way in the past,
but
> get a lot of great mileage with one-liners in the middle of pipes. the
> challenge becomes how to file away the useful ones for future recycling.
:)
>
> cheers, Tim

If I need to get pattern-matching info from the shell, I generally
write in a C-like way, use "match" and "[g]sub" to do the work, and
have my patterns as strings in quotes instead of patterns in slashes.

But then, I also tend to write long (1000+ lines) gawk programs using
both getline (oh the horror!) and patterns from standard input.

To show how far behind the times I am (using awk for over 15 years
now), I have started learning perl. One of these days, I may move from
fortran 77 to fortran 20xx.




 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:58:34 CDT 2008.