Hi all,
I have file a.dat with content
0,ID,,
1,001,2015060,UB0085000,Key2,abc,xyz
1,338,2015103,UB0085000,Key1,abc,xyz
1,338,2015103,UB0085000,Key5,abc,xyz
1,338,20017457,UB0085000,Key3,abc,xyz
1,338,20017457,UB0085000,Key4,abc,xyz
9,9,2016-03-17-09.03.13.131313
and file b.dat
1,Key1,a.txt,b.txt,c.txt
1,Key3,x.txt,y.txt,z.txt
1,Key5,p.txt,q.txt,r.txt
1,Key2,l.txt,m.txt,n.txt
1,Key4,j.txt,k.txt,l.txt
9,9,2016-03-17-09.03.13.131313
Final output should be(Print 1st and last line of a.dat as it is)
1,Key1,a.txt,b.txt,c.txt
1,Key3,x.txt,y.txt,z.txt
1,Key5,p.txt,q.txt,r.txt
1,Key2,l.txt,m.txt,n.txt
1,Key4,j.txt,k.txt,l.txt
9,9,2016-03-17-09.03.13.131313
Requirement :
I have to update file a.dat with help of b.dat having condition that search 4th column value of a.dat in b.dat. If matches then update column 6,7,8 of a.dat with the values of column 3,4,5 of b.dat and shift existing column 6,7,8 value
to next of a.dat
My Code :
awk 'NR==FNR{A[$2]=$3; B[$2]=$4; C[$2]=$5; next} {$6=A[$5]; $7=B[$5]; $8=C[$5]}1' FS=, OFS=, b.dat a.dat
My Output :
0,ID,,,,,,
1,001,2015060,UB0085000,Key2,l.txt,m.txt,n.txt
1,338,2015103,UB0085000,Key1,a.txt,b.txt,c.txt
1,338,2015103,UB0085000,Key5,p.txt,q.txt,r.txt
1,338,20017457,UB0085000,Key3,x.txt,y.txt,z.txt
1,338,20017457,UB0085000,Key4,j.txt,k.txt,l.txt
9,9,2016-03-17-09.03.13.131313,,,,,
Current Problem
1st and last line also get proccessed and contain many `,`
existing values of a.dat of column 6,7,8 is not shifting next.
Please suggest solution to this problem ..