我试图将mysqldump输出文件转换为PostgreSQL兼容的SQL。 问题在于处理转义的string值。
我需要从:
VALUES('blah blah blah','second string \'with escaped\' quotes and multiple lines goes here',35,10,'meh')
至:
VALUES(E'blah blah blah',E'second string \'with escaped\' quotes and multiple lines goes here',35,10,E'meh')
注意在每个单引号string之前加上“E”。
这怎么能在sed中完成呢? 也可以打开使用其他正则expression式引擎,只要我可以stream式处理(在这里处理多GB文件)。
在我看来,这不是一个不常见的使用场景,所以我查看了PostgreSQL的网站,看看他们是否有解决scheme – 并且确实列出了几个工具来完成这个工作 。 希望他们中的一个对你有用。