awk's curly braces (regex)
rank1seeker at gmail.com
rank1seeker at gmail.com
Fri Nov 6 18:29:00 UTC 2015
On Wed, 04 Nov 2015 19:36:29 -0800
"Chris H" <bsd-lists at bsdforge.com> wrote:
> On Wed, 04 Nov 2015 13:53:18 -0700 Ian Lepore <ian at freebsd.org> wrote
>
> > On Wed, 2015-11-04 at 21:10 +0100, rank1seeker at gmail.com wrote:
> > > 10.2-RELEASE-p6
> > >
> > > # awk --version
> > > awk version 20121220 (FreeBSD)
> > >
> > > # echo 2015 | awk '/^[0-9]/ {print}'
> > > Prints '2015'
> > >
> > > # echo 2015 | awk '/^[0-9]{4}/ {print}'
> > > Won't
> > >
> > > Why range/interval specified via curly braces doesn't work.
> > > PS: Yes I've tried escaping it with backslahes and double
> > > backslahes, nada!
> > >
> > > man pages:
> > > --
> > > Regular expressions are as in egrep; see grep(1).
> > > --
> Your SHELL can be a "gatcha", as well.
I know my shell.
Soner or later it always ends up in script => /bin/sh
> >
> > For what it's worth, the manpage on a linux system I checked also
> > says the regex is like egrep, but then it points out that one
> > difference is "interval expressions" (curly brace stuff) which it
> > says are "likely to break old awk programs" so they're only enabled
> > if --posix or --re -interval options are given. Our awk doesn't
> > seem to support those options.
> >
> > I guess our awk might also avoid the interval expressions out of
> > caution for breaking old programs; maybe we need to add the options
> > to enable them, like gnu awk has.
> >
> > -- Ian
Then, mentioned part of man pages has been blindly pasted.
awk's curly braces don't work as regex in FreeBSD, nor can it be
enabled.
Here is a proof that regex curly part is matched literally:
# echo '2015{40}' | awk '/^[0-9]+{40}/ {print}'
2015{40}
You devs decide best solution for awk, but for start, you can edit man
pages at least.
Thx,
Domagoj
More information about the freebsd-hackers
mailing list