从外部来源,我得到巨大的 CSV 文件(大约 16GB),其中的字段可选地用双引号 (") 括起来。字段由分号 (;) 分隔。当字段在内容中包含双引号时,它会被转义作为两个双引号。
目前,我正在将这些导入到 MySQL 数据库中,该数据库了解""
.
我正在考虑迁移到 Amazon Redshift,但他们(或者可能是一般的 PostgreSQL)要求使用反斜杠将引号转义为\"
.
现在我正在寻找最快的命令行工具(可能是 awk、sed?)以及转换文件的确切语法。
示例输入:
"""start of line";"""beginning "" middle and end """;"end of line"""
12345;"Tell me an ""intelligent"" joke; I tell you one in return"
54321;"Your mom is ""nice"""
"";"";""
"However, if;""Quotes""; are present"
示例输出:
"\"start of line";"\"beginning \" middle and end \"";"end of line\""
12345;"Tell me an \"intelligent\" joke; I tell you one in return"
54321;"Your mom is \"nice\""
"";"";""
"However, if;\"Quotes\"; are present"
编辑:添加了更多测试。