2

I have a file:

$ cat file
1,,"3.1,3.2",4,5

and because of the quotes I'm using FPAT = "([^,]*)|(\"[^\"]+\")") instead of just FS=",". I'm trying to replace a field, lets say $4, with another value:

$ gawk 'BEGIN{FPAT="([^,]*)|(\"[^\"]+\")"; OFS=","}{$4="new"; print}' file
1,,"3.1,3.2",new,,5
$ # right here  ^

but I get a duplicated , (OFS) after the replaced field. It gets duplicated when modifying any field except last field or empty fields.

Are you guys seeing this or is it just me in need of glasses 8| ? I'm using GNU Awk 4.1.3.

Edit:

A-ha, it must be an old bug. 4.1.1 duplicates the comma but 4.1.4 doesn't.

James Brown
  • 36,089
  • 7
  • 43
  • 59

1 Answers1

1

Apparently it's a bug in GNU awk prior to version 4.1.4.

James Brown
  • 36,089
  • 7
  • 43
  • 59
  • Answering this myself to close the question and to keep the info available here. – James Brown Apr 25 '18 at 08:40
  • 2
    Not sure how I missed this question at the time but in particular, it's this bug up to 4.1.3: https://lists.gnu.org/archive/html/bug-gawk/2015-09/msg00033.html. Note that the fix for that bug caused this other bug in 4.1.4: https://lists.gnu.org/archive/html/bug-gawk/2017-04/msg00000.html so get yourself onto gawk 4.2 if you're using FPAT :-). – Ed Morton Sep 09 '18 at 14:02