2017-06-09 3 views
0

Ich versuche, zwei CSV-Dateien auf diese Weise mit BASH zu fusionieren.Fuse zwei CSV-Dateien

files1.csv:

Col1;Col2 
a;b 
b:c 

file2.csv

Col3;Col4 
1;2 
3;4 

Result.csv

Col1;Col2;Col3;Col4 
a;b;0;0 
b;c;0;0 
0;0;1;2 
0;0;3;4 

Die ‚0'en in den Ergebnisdateien sind nur leere Zellen. Ich habe versucht, mit Paste Befehl, aber es fusioniert es nicht, wie ich will.

paste -d';' file1 file2 

Gibt es eine Möglichkeit, es mit BASH zu tun?

Danke.

Antwort

1

One in awk:

$ awk -v OFS=";" ' 
FNR==1 { a[1]=a[1] (a[1]==""?"":OFS) $0; next } # mind headers 
FNR==NR { a[NR]=$0 OFS 0 OFS 0; next }    # hash file1 
     { a[NR]=0 OFS 0 OFS $0 }     # hash file2 
END  { for(i=1;i<=NR;i++)if(i in a)print a[i] } # output 
' file1 file2 
Col1;Col2;Col3;Col4 
a;b;0;0 
b:c;0;0 
0;0;1;2 
0;0;3;4 
+1

Danke, es funktioniert! – Bvcawn

Verwandte Themen