问题描述
我有一个文件
:
$ cat file
1,,"3.1,3.2",4,5
并且由于使用了引号,我正在使用 FPAT =([[^,] *)|(\" [^ \] + \"))
而不只是 FS =","
.我正在尝试用另一个值替换 $ 4
字段,
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 ^
但是在替换字段之后,我得到了重复的
( OFS
).修改除最后一个字段或空字段以外的任何字段时,它都会重复.
but I get a duplicated ,
(OFS
) after the replaced field. It gets duplicated when modifying any field except last field or empty fields.
你们是看到这些还是只是我需要眼镜8 |?我正在使用GNU Awk 4.1.3.
Are you guys seeing this or is it just me in need of glasses 8| ? I'm using GNU Awk 4.1.3.
哈,一定是个老错误.4.1.1复制逗号,但4.1.4不复制.
A-ha, it must be an old bug. 4.1.1 duplicates the comma but 4.1.4 doesn't.
推荐答案
显然,这是4.1.4版之前的GNU awk中的错误.
Apparently it's a bug in GNU awk prior to version 4.1.4.
这篇关于GNU awk,FPAT以及重复FS带来的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!