gpt4 book ai didi

python - 通过 bash 替换单个 CSV 字段中的额外双引号

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:45 24 4
gpt4 key购买 nike

我需要替换 CSV 日志文件中的额外双引号(字段以逗号分隔并用双引号引起来)。替换必须仅影响 CSV 的最后一个字段。

输入日志文件示例:

"24-12-2015","23:07:08","00","01","00","00","START","00","END","JS786JGDG7899JSGJHG"dsdajasghsahd"

预期输出:

"24-12-2015","23:07:08","00","01","00","00","START","00","END","JS786JGDG7899JSGJHG''dsdajasghsahd"

我需要在 bash 或 python 中完成此任务。

最佳答案

您可以使用 awk:

awk "{gsub(/'/, \"''\", \$NF)} 1" file.csv

"24-12-2015","23:07:08","00","01","00","00","START","00","END","JS786JGDG7899JSGJHG''dsdajasghsahd"

关于python - 通过 bash 替换单个 CSV 字段中的额外双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38787354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com