Pattern Matching in Columns

Posted by Chronicles on Stack Overflow See other posts from Stack Overflow or by Chronicles
Published on 2012-09-12T14:23:25Z Indexed on 2012/09/12 15:38 UTC
Read the original article Hit count: 280

Filed under:
|
|
|
|

File 1

A11;F1;BMW
A23;F2;BMW
B12;F3;BMW
H11;F4;JBW

File 2

P01;A1;0;0--00  ;123;456;150
P01;A11;0;0--00  ;123;444;208
P01;B12;0;0--00  ;123;111;36
P01;V11;0;0--00  ;123;787;33.9

Output

-;-;-;P01;A1;0;0--00  ;123;456;150
A11;F1;BMW;P01;A11;0;0--00  ;123;444;208
B12;F3;BMW;P01;B12;0;0--00  ;123;111;36
-;-;-;P01;V11;0;0--00  ;123;787;33.9

I TRIED

awk 'FNR==NR {a[$2] = $0; next }{ if($1 in a) {p=$1;$1="";print a[p],$0}}' File1 File2 

But didnt work.

Basically I want to get the details from FILE 1 and compare with FILE2 (master list) .

Example :

A1 in FILE2 was not available in FILE1 , so in output file we have “-“ for 1st three fields and rest from FILE2 . Now, we have A11 and we got the detail in FILE1. So we write details of A11 from both File 1 & 2

© Stack Overflow or respective owner

Related posts about perl

Related posts about bash