Hello experts, I want to join a file with files whosE names are mentioned in one of the columns of the same file.
File 1
t1,a,b,file number 1
t1,a,c,file number 1
t2,c,d,file number 2
t2,c,e,file number 2
t2,c,f,file number 2
t2,c,g,file number 2
t3,e,f,file number 3
file number 1
t,h1,h2,c1,c2,c3
t1,a,b,v1,v2,v3
t1,x,y,g1,g2,g3
t1,a,b,v4,v5,v6
t1,x,y,h1,h2,h3
t1,a,b,v7,v8,v9
t1,a c,t1,t2,t3
t1,a,c,t2,t3,t4
file number 2
t,h1,h2,c11,c12,c13
t2,c,d,v11,v12,v13
t2,x,y,g11,g12,g13
t2,c,e,v14,v15,v16
t2,c,f,h11,h12,h13
t2,c,g,v17,v18,v19
file number 3
t,h1,h2,c12,c22,c23
t3,e,f,v31,v32,v33
t3,x,y,g11,g12,g13
t3,e,f,v34,v35,v36
t3,e,f,h31,h32,h33
t3,e,f,v37,v38,v39
I want to read each line of File, make a key of cols 2 and 3, and then extract data for the key from the filename mentioned in the 4th column. The filenames have spaces as I have shown. Also I want the headers in the output.
out_t1
t,h1,h2,c1,c2,c3
t1,a,b,v1,v2,v3
t1,a,b,v4,v5,v6
t1,a,b,v7,v8,v9
t1,a c,t1,t2,t3
t1,a,c,t2,t3,t4
out_t2
t,h1,h2,c11,c12,c13
t2,c,d,v11,v12,v13
t2,c,e,v14,v15,v16
t2,c,f,h11,h12,h13
t2,c,g,v17,v18,v19
out_t3
t,h1,h2,c12,c22,c23
t3,e,f,v31,v32,v33
t3,e,f,v34,v35,v36
t3,e,f,h31,h32,h33
t3,e,f,v37,v38,v39
This is what I want to do:-
awk -F, 'NR==FNR {k[$2$3]=$4;next} $2$3 in k { print }' OFS="," file1 $4 >> out_$1
Not sure how to take out the 4th column and 1st column from first file, also to extract the header.
Please assist.