Quantcast
Channel: UNIX and Linux Forums
Viewing all articles
Browse latest Browse all 16232

Match and append - awk

$
0
0
ALL,

Please help with this ...


File1
Code:


000433,ds00d11,tdev,ds00d11_view,0CD3
000433,ds00d12_34,tdev,ds00d12_view,132D

File2
Code:

CG01_ds00d11_drs,rs1_ds00d11_0CD3_114D,000433,0CD3                           
CG01_ds00d11_drs,rs1_ds00d11_0CD3_114D,000566,114D                         
 CG02_ds00d12_34_drs,rs2_ds00d12_132D_114F,000433,132D
CG02_ds00d12_34_drs,rs2_ds00d12_132D_114F,000566,114F

$5 in line1(file1) matches to $4 in line1(file2) , get value of $2 from line1(file2)
$2 in line1(file2) matches to $2 line2(file2) , get $1,$3,$4 from that line and append after $5 line1(file1)
Same logic to be used for rest
There will be always 2 occurrences where $2 in line2 matches

Output
Code:

000433,ds00d11,tdev,ds00d11_view,0CD3,CG01_ds00d11_drs,000566,114D
000433,ds00d12_34,tdev,ds00d12_view,132D,CG02_ds00d12_34_drs,000566,114F

Thanks

Viewing all articles
Browse latest Browse all 16232

Trending Articles