bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] FPAT bug?


From: Ed Morton
Subject: Re: [bug-gawk] FPAT bug?
Date: Sat, 1 Apr 2017 16:27:46 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

FWIW it looks like users can work around it for now by re-setting FPAT for every record:

$ cat tstFPAT.awk
BEGIN { FPAT="[^,]*" }
{
    oFPAT=FPAT; FPAT=""; FPAT=oFPAT

    print NF, $0
    for (i=1;i<=NF;i++)
        print 1, "\t" i, "[" $i "]"
    print ""
}

$ awk -f tstFPAT.awk file1.csv
3 ,,3
1       1 []
1       2 []
1       3 [3]

3 ,,3
1       1 []
1       2 []
1       3 [3]

Might be useful until a fix is available. Any better ideas for now?

Regards,

     Ed.

On 4/1/2017 12:08 PM, Andrew J. Schorr wrote:
On Sat, Apr 01, 2017 at 10:28:47AM -0500, Ed Morton wrote:
OK, thanks for the update!
Just to confirm that this is a bug: I think the results must be
consistent with the patsplit function. In 4.1.4, it says:

bash-4.2$ ./gawk 'BEGIN {nf = patsplit(",,3", f, "[^,]*"); for (i = 1; i <= nf; i++) 
printf "%d [%s]\n", i, f[i]}'
1 []
2 []
3 [3]

That is clearly inconsistent with:

bash-4.2$ (echo ,,3; echo ,,3) | ./gawk -v "FPAT=[^,]*" '{for (i = 1; i <= NF; i++) 
printf "%d [%s]\n", i, $i}'
1 []
2 []
3 [3]
1 []
2 [3]

So 4.1.4 is internally inconsistent; the first record was parsed correctly, but
the second was not.  The only remaining question is how to fix this properly...

Regards,
Andy





reply via email to

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