pointyhat
pointyhat

Reputation: 23

Why is my awk match not working?

I've got the following awk script:

/^[0-9]\{2\}$/ { print "found 2 digits"; }

I am running with the following command line into gawk:

gawk -f script.awk data.txt

The data file is

aa
32
gh

I am expecting one instance of "found 2 digits" to appear on stdout but I'm getting nothing. Any ideas? It appears to be related to the quantifier of {2} after some experimentation.

Upvotes: 2

Views: 1082

Answers (1)

codaddict
codaddict

Reputation: 455410

You need to specify --re-interval option.

Ideone Link

Alternatively you can also specify --posix option.

Ideone Link

Also you need to drop the \ from in front of { and }.

Upvotes: 4

Related Questions