common entries between files based on 1st column

Hi,

I am trying to get the common entries from 2 files based on 1st field.. However when I try to do in perl I am getting blank output.. How can I do this in awk?

open(BUFF1, "my_genes");
open(BUFF3, "rawcounts");
#open(WRBUFF,">result_rawcounts");
while($line =<BUFF1>)
{
        chomp($line);
        $line =~ s/ //g;
        @array = split(/\t/,$line);
        chomp($array[0]);
        $hash{$array[0]} = 1;
        $hash1{$array[0]} = $line;
}
while($line =<BUFF3>)
{
        chomp($line);
        $line =~ s/ //g;
        @array = split(/\t/,$line);
        chomp($array[0]);
        #if(exists($hash1{uc($array[0])}))
        if($hash{$array[0]} == 1)
        {
              print WRBUFF $line."\t".$hash1{$array[0]}."\n";
        }

}

input file1

chr4:134468319-134473843        311
chr7:13796245-13837410  312
chr7:13733505-13779637  313
chr7:13909676-13989588  314
chr7:13623966-13670807  315
chr7:14222402-14254870  316
chr10:33857721-33879475 317
chr15:44671855-44805829 318

input file2

chr1:3005029-3005778    CUFF.1  -       -       CUFF.1  -       -       -       -       0.611392        0.258405        0.964379        OK
chr1:3023637-3024298    CUFF.2  -       -       CUFF.2  -       -       -       -       0.616067        0.212809        1.01933 OK
chr1:3066843-3068300    CUFF.3  -       -       CUFF.3  -       -       -       -       0.312212        0.140913        0.483512        OK

Now I want to pick only rows from file 2 which have a key value(1st column) similar to the 1st column in file 1

Thanks,

You're getting what you asked for. There are no lines in file1 starting with "chr1:".

Hi,

I just pasted the sample file.. But I do have common ids from column 1 in 2 files.. I tried to debug the perl code and I see that my split function is not working..

Thanks,

Post representative data, then.