0

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.

4
0

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.