github.com/benhoyt/goawk@v1.8.1/testdata/gawk/widesub4.awk (about)

     1  # Date: Sun, 28 May 2006 11:20:58 +0200
     2  # From: Frantisek Hanzlik <franta@hanzlici.cz>
     3  # Subject: sub() function do'nt alter string length in awk 3.1.5
     4  # To: bug-gawk@gnu.org
     5  # Message-id: <44796B7A.3050908@hanzlici.cz>
     6  # 
     7  # Hello,
     8  # I not know when it is my mistake or gawk bug - in simple example below
     9  # I delete some chars from string variable, and after this string is
    10  # modified, but its length is unchanged.
    11  # 
    12  # awk 'BEGIN{A="1234567890abcdef";
    13  #   for (i=1;i<6;i++){print length(A),"A=" A ".";sub("....","",A)}
    14  # }'
    15  # 16 A=1234567890abcdef.
    16  # 16 A=567890abcdef.
    17  # 16 A=90abcdef.
    18  # 16 A=cdef.
    19  # 16 A=.
    20  # 
    21  # When I use gensub() instead of sub(), result is as I expected:
    22  # 
    23  # awk 'BEGIN{A="1234567890abcdef";
    24  #   for (i=1;i<6;i++){print length(A),"A=" A ".";A=gensub("....","",1,A)}
    25  # }'
    26  # 16 A=1234567890abcdef.
    27  # 12 A=567890abcdef.
    28  # 8 A=90abcdef.
    29  # 4 A=cdef.
    30  # 0 A=.
    31  # 
    32  # OS/GAWK versions:
    33  # - GNU/Linux kernel 2.6.16-1.2122_FC5 #1 i686, Fedora Core 5 distro
    34  # - glibc-2.4-8
    35  # - GNU Awk 3.1.5
    36  # 
    37  # Yours sincerely
    38  # Frantisek Hanzlík
    39  # 
    40  # == Lucní 502        Linux/Unix, Novell, Internet   Tel: +420-373729699 ==
    41  # == 33209 Stenovice   e-mail:franta@hanzlici.cz     Fax: +420-373729699 ==
    42  # == Czech Republic        http://hanzlici.cz/       GSM: +420-604117319 ==
    43  # 
    44  # 
    45  # 
    46  # #####################################################################################
    47  # This Mail Was Scanned by 012.net AntiVirus Service3- Powered by TrendMicro Interscan
    48  # 
    49  BEGIN{A="1234567890abcdef";
    50     for (i=1;i<6;i++){print length(A),"A=" A ".";sub("....","",A)}
    51  }