-1

我有一个这样的文件:

col1×col2×col3
12×"Some field with "quotes" inside it"×"Some field without quotes inside"

我想用单引号替换内部双引号,所以结果将如下所示:

col1×col2×col3
12×"Some field with 'quotes' inside it"×"Some field without quotes inside"

我想这可以用 sed、awk 或 ex 来完成,但我还没有找到一种干净快速的方法。真正的 CSV 文件大约有数百万行。

优选的解决方案是使用上述程序的单线。

提前谢谢了!

4

1 回答 1

0

根据您的字段分隔符×,使用 sed 的简单解决方法可能是:

 sed -E "s/([^×])\"([^×])/\1'\2/g" file

"这会将前面和后面的任何字符替换为×, '

请注意,sed 不支持正向前瞻,因此我们必须对模式进行分组并重新插入。

于 2018-06-04T13:14:29.983 回答