bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Fwd: why does referencing NF or different fields change $


From: Aharon Robbins
Subject: Re: [bug-gawk] Fwd: why does referencing NF or different fields change $0 after recompilation?
Date: Fri, 18 Sep 2015 14:47:41 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Hi.

Re this:

> To: address@hidden
> From: Ed Morton <address@hidden>
> Date: Thu, 17 Sep 2015 08:04:10 -0500
> Subject: [bug-gawk] Fwd: why does referencing NF or different fields change
>  $0 after recompilation?
>
> I got a couple of responses to my question below on comp.lang.awk and I'm now 
> pretty confident it's a bug and not my misunderstanding of something.
>
> Josef Frank pointed out that:
>
> > Reminds me of a bug (in gawk 4.0.0) mentioned at the top of:
> > http://git.savannah.gnu.org/cgit/gawk.git/tree/test/pty1.awk
>
> Can you take a look?
>
>       Ed.
>
> -------- Forwarded Message --------
> Subject: why does referencing NF or different fields change $0 after 
> recompilation?
> Date: Wed, 16 Sep 2015 22:15:05 -0500
> From: Ed Morton <address@hidden>
> Organization: A noiseless patient Spider
> Newsgroups: comp.lang.awk
>
> This GNU awk script is intended to replace commas with semi-colons in a CSV 
> file
> that could contain commas in the quoted fields and could have blank fields:
>
> $ awk -v FPAT='([^,]*)|("[^"]+")' -v OFS=';' '{$1=$1}1' file
>
> Can anyone explain why the first call to awk below replaces the first comma 
> with
> two semi-colons while the second and third (which are only different from the
> first in that they mentions NF somewhere in the action block) replace it with
> one, which is the desired result?
>
> $ cat file
> "A","B","C"
>
> $ awk -v FPAT='([^,]*)|("[^"]+")' -v OFS=';' '{$1=$1}1' file
> "A";;"B";"C"

The following patch does the trick.  I will push it, and add this
to the test suite, shortly.

Thanks,

Arnold
--------------------------------------------------
diff --git a/field.c b/field.c
index 6a7c6b1..ed31098 100644
--- a/field.c
+++ b/field.c
@@ -1598,9 +1598,8 @@ fpat_parse_field(long up_to,      /* parse only up to 
this field number */
 
        if (in_middle) {
                regex_flags |= RE_NO_BOL;
-               non_empty = rp->non_empty;
-       } else
-               non_empty = false;
+       }
+       non_empty = rp->non_empty;
 
        eosflag = false;
        need_to_set_sep = true;



reply via email to

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