gsub() ignoring word boundary # echo 'abc' | awk '{ gsub(/\<b*/,""); print; }' ac # echo 'abc' | awk '{ sub(/\<b*/,""); print; }' abc Probably something to do with backtracking.... Compare gawk: $ echo 'abc' | awk '{ gsub(/\<b*/,""); print; }' abc $ echo 'abc' | awk '{ sub(/\<b*/,""); print; }' abc Seen on media player BusyBox v1.12.4 (2008-12-31 22:38:12 CET) multi-call binary Linux hdx 2.6.15-sigma #953 PREEMPT Wed Jun 3 21:49:15 CST 2009 mips unknown and router BusyBox v1.12.3 (2008-12-14 02:54:58 PST) built-in shell (ash) Linux unknown 2.4.20 #1 Sun Dec 14 03:03:26 PST 2008 mips unknown
I see where it happens. Added comments in awk_sub() about it. Unfortunately, no easy fix. Need to use GNU regex matching, not POSIX one, to do it right.
commit 2ca39ffd447ca874fcea933194829717d5573247 Date: Thu Jun 8 10:42:39 2023 +0200 awk: fix subst code to handle "start of word" pattern correctly (needs REG_STARTEND)