Matching pattern in two files and print the line

Hi,

I want to match the pattern in file1 with file2 and print the value in file2 and paste in file1
file1:

ISHO RT SR                                Major     96.46778
Drop Call Rate CS                       Critical  0.5072662
ISHO RT SR                                Major     97.754364
Active HS-DSCH MAC-d          Critical  1979.25
ISHO RT SR                                Major     97.31076

file2:

RRC Stup RNC Failures   0.1
Active HS-DSCH MAC-d    2000    
Drop Call Rate PS       0.8
ISHO RT SR    96

I want the output:

ISHO RT SR                                Major     96.4        96
Drop Call Rate PS                       Critical  0.50         0.8
ISHO RT SR                                Major     97.75      96
Active HS-DSCH MAC-d          Critical  1979.25   2000
ISHO RT SR                                Major     97.3       96

I tried grep each pattern:

grep -i 'pattern' file1 file2 ',awk '{$0}''

It's not working

Your data format is not scripting friendly (no clear delimiter between fields). Anyway... Try this:

awk 'NR==FNR{x=$NF;$NF="";sub(" $","",$0);a[$0]=x;next}{for (i in a) if ($0~i) $(NF+1)=a}1' file2 file1

The example you've provided is ambiguous or need some precisions.

example : in your file1 :

Drop Call Rate CS ...

in your file2 :

Drop Call Rate PS ...

in your output :

Drop Call Rate PS ...

Should we suppose that you check the matching on the 3 first words only?
Or is you file TAB delimited and should the matching be based on the whole first field ?

Thanks,

I used :

awk 'NR==FNR{x=$NF;$NF="";sub(" $","",$0);a[$0]=x;next}{for (i in a) if ($0~i) $(NF+1)=a}1' file2 file1

and paste the values fine.

What about line up the last two vaules (How I can interpret \t tab for insertion to line up the value in same column and get the output:

ISHO RT SR  Major     96.4  96
Drop Call Rate PS Critical  0.50  0.8
ISHO RT SR  Major     97.75  96
Active HS-DSCH MAC-d Critical  1979.25 2000
ISHO RT SR  Major     97.3  96