Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge two single column csv files with linux commands

Tags:

linux

csv

I was wondering how to merge two single column csv files into one file where the resulting file will contain two columns.

file1.csv
   first_name
   chris
   ben
   jerry

file2.csv
   last_name
   smith
   white
   perry

result.csv
   first_name,last_name
   chris,smith
   ben,white
   jerry,perry

Thanks

like image 538
user1328191 Avatar asked Nov 29 '22 17:11

user1328191


2 Answers

$ cat file1
John
Mary
$ cat file2
Smith
Jones
$ paste -d, file1 file2
John,Smith
Mary,Jones

The -d, argument is used to designate commas as the delimiter between columns

like image 193
ghoti Avatar answered Dec 06 '22 07:12

ghoti


You're looking for paste.

like image 44
Ignacio Vazquez-Abrams Avatar answered Dec 06 '22 07:12

Ignacio Vazquez-Abrams