Wednesday, March 30, 2011

does awk support quantifiers - i want [0-9]{6,6}

gawk doesn't seem to match six digit fields - or n digit fields using the {n,m} quantifiers

It does match [0-9][0-9][0-9][0-9][0-9][0-9] ok.

Doesn't seem to support \d\d\d\d\d\d either.

Do i need to turn on extended reg ex, or does it just not support that.

Tnx

From stackoverflow
  • You need to specify the "--re-interval" (or "-W re-interval") flag to take advantage of this behavior.

    echo 12345 | gawk --re-interval '/[0-9]{5}/{print}{}'
    12345
    echo 12345 | gawk --re-interval '/[0-9]{6}/{print}{}'
    <no output>
    
  • Expanding minimally on Pax's response, --posix also enables this behavior. Also, you are correct that gawk does not support the character class escapes (like \d) but it does support the [[:digit:]] syntax.

0 comments:

Post a Comment