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
  • 720
dyedfox
  • 343

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
  • 136,215
  • 21
  • 243
  • 336
  • Thank you very much for the answer! Yes, you are right - the desktop version uses mawk indeed. P.S. Thanks. I have made a mistake by copying the wrong line from the history. Thanks. – dyedfox Jul 26 '22 at 20:53
  • Also helpful might be dpkg -S $(which awk) -- which package does awk come from? On my systems, it isn't from a package. – dannyman Jul 27 '22 at 00:07
  • 1
    @dannyman note that since Ubuntu systems implemented the "usrmerge", things like dpkg -S $(which awk) may no longer work as expected (depending on the order of /bin and /usr/bin in your PATH). See for example Where does /usr/bin/grep come from in Ubuntu Focal – steeldriver Jul 27 '22 at 00:23