bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

setting RS to null changes field splitting with the default FS


From: Ed Morton
Subject: setting RS to null changes field splitting with the default FS
Date: Tue, 31 Mar 2020 17:25:35 -0400
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0

Setting RS to null in gawk (tested with version 4.1.4 on Mac and 5.0.1 on cygwin) seems to change how field splitting works with the default FS.

I understand this:

   $ echo ' a b c ' | awk '{print NF, "<" $0 ":" RT ">"; for (i=1;
   i<=NF; i++) print i, "[" $i "]"}'
   3 < a b c :
    >
   1 [a]
   2 [b]
   3 [c]

because the default FS setting is causing leading/trailing white space to be ignored when the record is split into fields but now look at this:

   $ echo ' a b c ' | awk -v RS='' '{print NF, "<" $0 ":" RT ">"; for
   (i=1; i<=NF; i++) print i, "[" $i "]"}'
   4 < a b c :
    >
   1 [a]
   2 [b]
   3 [c]
   4 []

Why is there a 4th field? I THINK it's a bug that in that 2nd script the trailing white space is not ignored when the record is split into fields. FWIW I tested that last script with OSX/BSD awk too and it did strip off the trailing blank and leave 3 fields as I expected.

    Ed.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]