Okan Albayrak
Okan Albayrak

Reputation: 49

Joining 2 csv files in OS X

I want to join 2 csv files, e.g.

A,B
1,2

and

C,D
1,3

to

A,B,C,D
1,2,1,3

I had tried it out with

cat *.csv >merged.csv

But it doesnt reach the goal, that I want. Can anyone helps me

Upvotes: 0

Views: 588

Answers (1)

riteshtch
riteshtch

Reputation: 8769

cat stands for concatenate, it prints the 1st file and then the content of 2nd file after it not next to it. So using cat you cant achieve your output:

$ cat *.csv
A,B
1,2
C,D
1,3
$

You can use the paste command which paste's lines from 2 files side by side i.e line 1 from file 1 is pasted before line 1 from file 2.

$ cat file1.csv 
A,B
1,2
$ cat file2.csv 
C,D
1,3
$ paste -d ',' file1.csv file2.csv > newfile.csv
$ cat newfile.csv
A,B,C,D
1,2,1,3
$

-d , means delimiter must be comma.

Upvotes: 3

Related Questions