Using Join Command

Greetings,
I am attempting to use the join command to produce a file from 2 sorted comma seperated files. Ex.:
FILE 1:
jane,dow
joe,blow

FILE 2:
jane,dow,50,50,20
joe,blow,29,53,25
spike,lee,50,91,05

I want the resulting file to be reconds in FILE 2 where the person exists in FILE 1. ex:

joe,blow,29,53,25
jane,dow,50,50,20

I've tried using join -t, -j1 1 -j1 2 -j2 1 -j2 2 -o "2.1 2.2 2.3 2.4 2.5" FILE1 FILE 2 but it seems to only give me the first record matched (joe,blow,29,53,25). I expect the number of records in the resulting file to be the same as that of FILE 1.

Any help would be appreciated to resolve my problem.
Thanks,
Marcel Sammut

how about:

#!/bin/sh
while read line
do
    grep "$line" /path/to/file2 >> file3
done < /path/to/file1

Try...

fgrep -f file1 file2

With trhe these two solutions, too many records may be selected.
For example, the following record in file2 will be selected :

big-joe,blow,29,53,25

A little modification to Hadarot code :

#!/bin/sh
while read line
do
    grep "^$line," /path/to/file2 >> file3
done < /path/to/file1

Another solution with awk :

awk '
BEGIN {
   FS = ",";
   while (getline < ARGV[1])
      persons[$0]++;
   ARGV[1]="";
} 
{
   person = $1 "," $2;
   if (person in persons) print;
} ' /path/to/file1 /path/to/file2

Jean-Pierre.

Thanks for all those who've replied.

I've figured out how to use the join command for this task. Turns out join only works on one column key. So I had to concatenate the "first name" with the "last name" (i.e.: joe|blow,29,53,25 - where i used pipe to seperate the two keys).

With the use of cut and paste commands, I managed to get what I wanted.

I did try the posted suggestions, however, my application is a bit more complicated than my sample files.

Cheers,
Marcel