融合两个 csv 文件

Fuse two csv files

我正在尝试使用 BASH 以这种方式融合两个 csv 文件。

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

结果文件中的“0”只是空单元格。 我尝试使用粘贴命令,但它没有按照我想要的方式融合它。

paste -d';' file1 file2 

有没有办法使用 BASH 来做到这一点?

谢谢。

awk 中的一个:

$ awk -v OFS=";" '
FNR==1  { a[1]=a[1] (a[1]==""?"":OFS) [=10=]; next }    # mind headers
FNR==NR { a[NR]=[=10=] OFS 0 OFS 0; next }              # hash file1
        { a[NR]=0 OFS 0 OFS [=10=] }                    # 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