我正在使用流编辑器 sed 将大量文本文件数据 (400MB) 转换为 csv 格式。
我已经非常接近完成,但突出的问题是引号中的引号,在这样的数据上:
1,word1,"description for word1","another text",""text contains "double quotes" some more text"
2,word2,"description for word2","another text","text may not contain double quotes, but may contain commas ,"
3,word3,"description for "word3"","another text","more text and more"
所需的输出是:
1,word1,"description for word1","another text","text contains double quotes some more text"
2,word2,"description for word2","another text","text may not contain double quotes, but may contain commas ,"
3,word3,"description for word3","another text","more text and more"
我四处寻找帮助,但我并没有太接近解决方案,我尝试了以下带有正则表达式模式的 seds:
sed -i 's/(?<!^\s*|,)""(?!,""|\s*$)//g' *.txt
sed -i 's/(?<=[^,])"(?=[^,])//g' *.txt
这些来自以下问题,但似乎不适用于 sed:
原始文件是 *.txt,我正在尝试使用 sed 编辑它们。