我有以下格式的数据。
abc ssg,"-149,684.58","-149,469.05",-215.53
efg sfg,-80.99,-77.46,-3.53
hij sf,"4,341.23","4,131.90",209.33
kilm mm,"2,490,716.13","-180,572.48","9,223.06"
我想在末尾添加双引号,而不是通过perl或unix完成双引号
输出应如下所示:
abc ssg,"-149,684.58","-149,469.05","-215.53"
efg sfg,-80.99,-77.46,"-3.53"
hij sf,"4,341.23","4,131.90","209.33"
kilm mm,"2,490,716.13","-180,572.48","9,223.06"
答案 0 :(得分:0)
这可能对您有用:
gawk -F ',' -v Q='"' 'BEGIN {OFS=FS} $NF !~ Q {gsub(/.*/,Q $NF Q,$NF); print ; next} 1' INPUTFILE
-F ','
设置输入字段分隔符-v Q='"'
将Q
变量设置为"
,这有助于避免一些逃避问题BEGIN {OFS=FS}
将输出字段分隔符设置为与输入$NF !~ Q
如果最后一个字段与Q
(=="
)不匹配,那么gsub(/.*/,Q $NF Q,$NF)
将最后一个字段替换为"
分隔print
行next
规则并处理下一行1
为每隔一行执行默认的打印行操作(最后一个字段与"
不匹配)