-1

Hi I have 3 csv files with different type of data in all, also no of rows is different in all the files. I want to merge them into a single csv file but when using "paste command data is being copied into output.csv but getting copied to next row not in different column.

file1.csv

CELBU,398
ORICE,1026
JSCUN,134250
BHARA,66
MOBTE,2041
RMO,65081 

file2.csv

8/22/2013,1417196108
8/23/2013,1370586883
8/24/2013,1362561606

file3.csv

ISBND,9 
BHARH,25

Desired output:

CELBU,398,8/22/2013,1417196108,ISBND,9
ORICE,1026,8/23/2013,1370586883,BHARH,25
JSCUN,134250,8/24/2013,1362561606
BHARA,66
MOBTE,2041
RMO,65081

Tried:

paste -d"," file1.csv file2.csv file3.csv > output.csv

Please suggest is this problem can be solved through perl or shell script.

4

1 回答 1

1

您可以将 pr 命令与合并一起使用:

文件1:

CELBU,398 
ORICE,1026 
JSCUN,134250 
BHARA,66 
MOBTE,2041 
RMO,65081 

文件2:

8/22/2013,1417196108
8/23/2013,1370586883
8/24/2013,1362561606

文件3:

ISBND,9 
BHARH,25

输入:

pr -tm -s, file1 file2 file3 > new

输出:

CELBU,398,8/22/2013,1417196108,ISBND,9
ORICE,1026,8/23/2013,1370586883,BHARH,25
JSCUN,134250,8/24/2013,1362561606
BHARA,66
MOBTE,2041
RMO,65081
  • -t, --omit-header 省略页眉和页尾
  • -m, --merge 并行打印所有文件,每列一个,截断行,但用 -J 连接全长行
  • -s 用单个字符分隔列

http://linux.about.com/library/cmd/blcmdl1_pr.htm

于 2013-09-07T19:28:52.343 回答