I'm having trouble using quantifier in a Awk Regex.

awk -F"|" -v col="$COUNTER" '$col ~ /doi\/tm-[a-z0-9]/ { print $col } ' OFS=, tmp.csv

This works fine, but I want to specify to the [a-z0-9] class a limit of 8 chars.

So I did :

awk -F"|" -v col="$COUNTER" '$col ~ /doi\/tm-[a-z0-9]{8}/ { print $col } ' OFS=, tmp.csv

It doesn't work, and :

awk -F"|" -v col="$COUNTER" '$col ~ /doi\/tm-[a-z0-9]\{8\}/ { print $col } ' OFS=, tmp.csv

doesn't work neither.

That's on a Ubuntu 20.04 system.

  • Which awk implementation are you using? What Unix are you running on? Possibly related: unix.stackexchange.com/questions/561772/…
    – Kusalananda
    Oct 16, 2020 at 14:30
  • I'm running Ubuntu 20.04
    – mgev
    Oct 16, 2020 at 14:33
  • 3
    I believe Ubuntu installs mawk by default which is not POSIX compliant and doesn't support regex interval operators (doesn't support POSIX character classes nor multibyte characters either). You can install gawk which should replace mawk with gawk for awk. Alternatively you could run busybox awk instead of awk. Oct 16, 2020 at 14:39
  • 2

1 Answer 1


Indeed, changing default awk to gawk solved the problem.

gawk -v col="$COUNTER" 'BEGIN{ FS = "|" } $col ~ /doi\/tm-[a-z0-9]{8}/ { print $col } 1' OFS=, tmp.csv

This works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.