I am trying to merge the contents of multiple files based on a key matching with awk, I have seen solutions only for two input files, but not more. The input files look like this:
file1
1#a1
2#b1
3#c1
4#d1
6#f1
file2
1#a2
2#b2
3#c2
5#e2
6#f2
file3
1#a3#extra_field_1
2#b3#extra_field_2
3#c3#extra_field_3
4#d3#extra_field_4
5#e3#extra_field_5
The desired output is the following:
output
a1;a2;a3;extra_field_1
b1;b2;b3;extra_field_2
c1;c2;c3;extra_field_3
d1;;d3;extra_field_4
;e2;3e;extra_field_5
For this, I am using a bash script based on awk command like the following:
$ awk -v OFS=';' -F '#' 'FNR==NR{a[$1]=$2;next} FNR!=NR{b[$1]=$2;next} NF==3{print a[$1],b[$1],$2,$3}' file1 file2 file3 > output
Anyway, it seems to obviate some of the inputs because it doesn't produce any output, any ideas?
Thanks.