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.


|