GNU awk, FPAT and trouble with a duplicating FS

妖精的绣舞 提交于 2021-01-28 04:45:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!