Short program to select lines from a file based on a second file

Hello,

I use UBUNTU 12.04.

I want to write a short program using awk to select some lines in a file based on a second file.

My first file has this format with about 400,000 lines and 47 fields:
SNP1 1 12.1
SNP2 1 13.2
SNP3 1 45.2
SNP4 1 23.4
My second file has this format:
SNP2
SNP3
SNP5
SNP10

I want to have an output like this:
SNP2 1 13.2
SNP3 1 45.2
SNP5 1 23.2
SNP10 1 45.2
That is I have basically the first file but only with the SNPs that exist in the second file, it is important that it gives me back the whole row.

I wrote a code as following but it does not work:

BEGIN{
OFS=ORS=" "
}
{
if(FILENAME==ARGV[1]){SNP_name[$1]=FNR}
if(FILENAME==ARGV[2]){
if($1 in SNP_name){sel[SNP_name[$1]]=$1}
{
print $0 > test
}

Thank you for any help.

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.