使用不同的列水平合并两个csv文件

时间:2014-05-26 20:23:21

标签: shell csv

我正在尝试水平合并两个csv文件。

我使用了这个命令:

paste -d ',' file1.csv file2.csv> results.csv

但它显示了与第二行csv输出的合并。像这样:

"Shares of Apple, Inc. near ex-dividend as it gears up to distribute $2.7 ...",Apple Inc. (AAPL),"May 8, 2014"

,0.125,0.0,pos

应该是这样的:

"Shares of Apple, Inc. near ex-dividend as it gears up to distribute $2.7 ...",Apple Inc. (AAPL),"May 8, 2014",0.125,0.0,pos

file1.csv

"Shares of Apple, Inc. near ex-dividend as it gears up to distribute $2.7 ...",Apple Inc. (AAPL),"May 8, 2014"
Apple Woos Dr. Dre With $3.2 Billion Offer for Beats to Fend Off Spotify as ...,Apple Inc. (AAPL),"May 8, 2014"

file2.csv

0.125,0.0,pos
0.0,0.75,neg

如何纠正这个问题?

1 个答案:

答案 0 :(得分:0)

是的@alvits。我使用以下文件将文件转换为unix文件:

 awk '{ gsub("\r", "\n"); print $0;}' macfile.txt > unixfile.txt

现在工作正常。