Adding a field to a file using a conversion table

Hello everyone,

Here is what i am trying to accomplish. I have a transaction log that I want to to add a field. The fields in the transaction log are tab delimited FYI. My goal is to add a column specifying the category/type to each item purchased. I have created a two column "conversion table" file that will give the category/type associated with each item.

Example Transaction Log:

Item     Amount      Item Name     Price
11        1              X                  $1.00
12        1              Y                  $1.00
15        1              W                 $1.00
12        1              Y                  $1.00
13        1              Z                  $1.00
12        1              Y                  $1.00
12        1              Y                  $1.00

Example Conversion Table:

Item     Category
11        Cat
12        Dog
13        Fish
14        Bird
15        Pig

Desired Output:

Item     Amount      Item Name     Price    Category
11        1              X                  $1.00    Cat
12        1              Y                  $1.00    Dog
15        1              W                 $1.00    Pig
12        1              Y                  $1.00    Dog
13        1              Z                  $1.00    Fish
12        1              Y                  $1.00    Dog
12        1              Y                  $1.00    Dog

I have been trying to do this with a bash script but I have having some with syntax and executing the commands. My thoguht process is to do it with sed, head, and awk. Is this the most effiecent way?

script.sh
#!/bin/bash
fname=$1
head -n 2000 $fname | awk -F t '{print $30, $32, $33, $33 - 0.40 ,$28}' > "cache.txt"
while read itemNo Category
do
     sed  -i s/"$itemNo"/"$Category"/g cache.txt > cache.txt
done < "key.txt" 

p.s. I pass in the filename as a parameter.

Thanks in advance.

Try this,

awk 'NR==FNR{a[$1]=$2;next} a[$1]{print $0,a[$1]}' ConversionTable TransactionLog

pravin27 I owe you a digital beer. You have saved me many hours of scratching my head. Thanks for quick response. I just inserted the code and changed the file names and Boom! It worked!