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: Backslash w...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 2227 of 2241
Post > Topic >>

Re: Backslash with interval expressions

by pk <pk@[EMAIL PROTECTED] > May 1, 2008 at 06:40 PM

On Thursday 1 May 2008 18:37, Prateek wrote:

> Hi,
> Thsi regular expression works for me:
> echo "hiiii" | gawk --posix '/i{2}/ {print "ji"}'
> ji
> 
> As per the gawk guide notes below:
> "However, because old programs may use `{' and `}' in regexp
> constants, by default gawk does not match interval expressions in
> regexps. If either --posix or --re-interval are specified (see
> Options), then interval expressions are allowed in regexps.
> 
> For new programs that use `{' and `}' in regexp constants, it is good
> practice to always escape them with a backslash. Then the regexp
> constants are valid and work the way you want them to, using any
> version of awk.14 "
> 
> I try backslah option as
> echo "hiiii" | gawk '/i\{2\}/ {print "ji"}'
> 
> But this does not give expected output. Can someone please help me
> with this.

Yuo are getting the expected output. What the manual says is that, if you
want gawk to treat { and } *literally* (ie, not as RE interval operators),
you better escape them always.
In your second example, you escape them and gawk treats them as regexp
constants, even if you use --re-interval or --posix.

-- 
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.




 2 Posts in Topic:
Backslash with interval expressions
Prateek <prateek.a@[EM  2008-05-01 09:37:35 
Re: Backslash with interval expressions
pk <pk@[EMAIL PROTECTE  2008-05-01 18:40:41 

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 10:51:56 CDT 2008.