On 2023-12-15 11:19, Zack Weinberg wrote:
[...]
> old non-GNU implementations of awk probably don't support using a
> regexp as the third argument to 'split'.  (I'm not 100% sure about
> this; the gawk manual is usually very good about pointing out
> portability issues but in this case it's ambiguous.

This fact is also explicitly mentioned in the Autoconf documentation[1]:

  In code portable to both traditional and modern Awk, FS must be a
  string containing just one ordinary character, and similarly for
  the field-separator argument to split.

The heirloom-tools package[2] includes a traditional awk with this
particular limitation.  This is a free software implementation (ported
from OpenSolaris) that can be installed on a modern GNU/Linux system.
It should be very similar to Solaris 10 /bin/awk:

  % echo abcdefg | heirloom-tools/5bin/awk '{ split($1, a, /c?e/); print a[2]; 
}'
  awk: syntax error near line 1

  % echo abcdefg | heirloom-tools/5bin/awk '{ split($1, a, "c?e"); print a[2]; 
}'
  defg

Even with AC_PROG_AWK, on ULTRIX it selects "nawk" which still does not
work with a regexp argument to split, but it does work if the argument
is a string which can be interpreted as a regexp:

  ultrix% echo abcdefg | nawk '{ split($1, a, /c?e/); print a[2]; }'
  [no output]

  ultrix% echo abcdefg | nawk '{ split($1, a, "c?e"); print a[2]; }'
  fg

[1] 
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/autoconf.html#Limitations-of-Usual-Tools
[2] https://heirloom.sourceforge.net/tools.html

Cheers,
  Nick

Reply via email to