问题
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.
回答1:
Apparently it's a bug in GNU awk prior to version 4.1.4.
来源:https://stackoverflow.com/questions/49031764/gnu-awk-fpat-and-trouble-with-a-duplicating-fs