我已经被这个问题困扰了几个小时,并尝试了许多不同的工具来完成任务,但都没有成功。如果有人能帮我解决这个问题,那就太好了。
问题如下:
我有一个非常大的CSV文件(400MB+),它的格式不正确。现在它看起来像这样:
This is a long abstract describing something. What follows is the tile for this sentence." ,Title1 This is another sentence that is running on one line. On the next line you can find the title. ,Title2
你可能已经看到了,标题",Title1"和",Title2"实际上应该与前面的句子在同一行。然后它将会变成这样:
This is a long abstract describing something. What follows is the tile for this sentence.",Title1 This is another sentence that is running on one line. On the next line you can find the title.,Title2
请注意,句子结尾可能包含引号,也可能没有。最终它们应该被替换掉。
以下是我目前想出的解决方案:
sed -n '1h;1!H;${;g;s/\."?.*,//g;p;}' out.csv > out1.csv
这应该能够匹配多行中的表达式,但不幸的是它并没有成功 :)
该表达式正在寻找句子末尾的点以及可选引号加上我试图与.*匹配的换行符。
非常感谢任何帮助。使用哪种工具都无所谓(awk、perl、sed、tr等)。