Look up Multiple files

Hi,

Need help for matching column from three different files and find the mismatch details to new output file

my files below:
a.txt

column1,column2, column3
1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,d,12-dec-12
5,e,11-nov-11
6,f,1-oct-13

b.txt

1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,f,
5,f,11-nov-11
6,f,1-oct-13

c.txt

1,1-jan-13
2,3-jan-13
3,5-jan-13
4,12-dec-12
5,11-nov-11
6,1-oct-13

Output Required in below format.

a.column1a.column2a.column3b.column2b.column3c.column21a1-Jan-13a1-Jan-131-Jan-132b3-Jan-13b3-Jan-133-Jan-133c5-Jan-13c5-Jan-135-Jan-134d12-Dec-12f12-Dec-125e11-Novf11-Nov11-Nov6f1-Oct-13f1-Oct-131-Oct-13

I totaly new to Unix Shell Script, and don't know how to code for the above output.

Please use code tag and provide desire o/p in proper format.

1 Like

Sorry for the unstructured sample output

a.txt
column1,column2, column3
1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,d,12-dec-12
5,e,11-nov-11
6,f,1-oct-13
 
b.txt
1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,f,
5,f,11-nov-11
6,f,1-oct-13

c.txt
1,1-jan-13
2,3-jan-13
3,5-jan-13
4,12-dec-12
5,11-nov-11
6,1-oct-13

Desired Output file can be in below format
 
a.column1,a.column2,a.column3,b.column2,b.column3,c.column2
1,a,1-Jan-13,a,1-Jan-13,1-Jan-13
2,b,3-Jan-13,b,3-Jan-13,3-Jan-13
3,c,5-Jan-13,c,5-Jan-13,5-Jan-13
4,d,12-Dec-12,f,,12-Dec-12
5,e,11-Nov-11,f,11-Nov-11,11-Nov-11
6,f,1-Oct-13,f,1-Oct-13,1-Oct-13

 

try below code

awk -F"," 'NR==FNR{a[$1]=$0;next} a[$1] {a[$1]=a[$1]","$2","$3} END {for (i in a) { print a}}' file1 file2 file3  | sed 's/,$//g' | sort -t"," -k1 -n
1 Like

Thanks Pravin, this has worked perfectly as per my requirement, however I was looking to get the column headings according to the file name, if you will see the output file format, I had given filename[.]column heading, can this be possible to print the same.

a.column1,a.column2,a.column3,b.column2,b.column3,c.column2