8

Just a simple question.

Why this bash command works properly on Ubuntu Server and finds out the ISBN code and doesn't work on my Ubuntu Desktop? Both systems are 22.04 LTS.

echo "ISBN 5-02-013850-9" | awk '/ISBN [0-9]{1}-[0-9]{2}-[0-9]{6}-[Xx0-9]{1}/ {print $0}'

Thanks in advance.

gronostaj
  • 750
dyedfox
  • 353

1 Answers1

9

Likely one of them is using gawk (GNU awk) while the other is mawk, which doesn't appear to support the RE brace quantifiers. Check with awk -W version.

mawk appears to be the default awk in Ubuntu 22.04, but if you subsequently install gawk it will take preference via the update-alternatives mechanism.

See Built-in regex's do not support brace-expressions.

As an aside, [Xx|0-9] should probably be [Xx0-9] (unless you're trying to match a literal |).

steeldriver
  • 142,475