samedi 27 juin 2015

awk full join 2 files on single column

I have 2 CSV files of which i want to join together using AWK.

file1.csv:

A1,B1,C1
"apple",1,2
"orange",2,3
"pear",5,4

file2.csv:

A2,D2,E2,F2
"apple",1,3,4
"peach",2,3,3
"pear",5,4,2
"mango",6,5,1

This is the output i want:

A1,B1,C1,A2,D2,E2,F2
"apple",1,2,"apple",1,3,4
"orange",2,3,NULL,NULL,NULL,NULL
"pear",5,4,"pear",5,4,2
NULL,NULL,NULL,"peach",2,3,3
NULL,NULL,NULL,"mango",6,5,1

I want to do a full join on file 1 and file2 where A1=A2. File2 has more rows than file1. For records that dont have matching column values, NULL values will be inserted instead.

Aucun commentaire:

Enregistrer un commentaire