Problem joining 2 files

Hi

I have 2 files which look like

File1

1245
1256
2345
2165
3245
9851
8514
6498
8547
2541
5242

and File2

2165,req,8421513,num,,,8475
8547,req,8484572,num,,,7548
3987,req,7638975,num,,,7483
1118,req,2423543,num,,,1254
5242,req,3452534,num,,,3245
1245,req,5423156,num,,,2345
.
.
.
and so on

Now all entries of File1 are present in File2 in first column.
I need to make a third file consisting of all the entries of File1 and there corresponding details from File2.
PS: File2 has many entries not in File1, and we don't need those entries in output file.

The output File for above sample of files is:

File3

1245,req,5423156,num,,,2345
2165,req,8421513,num,,,8475
8547,req,8484572,num,,,7548
5242,req,3452534,num,,,3245
.
.
.
.
and so on.

Thanks in advance.

Regards
Rochit

Did you try the join command?

join File1 File2

By default, the first field will be taken as the join key.

But the problem is that File 2 has many extra entries and all are placed randomly........

awk -F, 'NR==FNR {a[$1]=$0} NR!=FNR{print a[$1]}' file2 file1 | sed '/^$/d'

where,
file2 --> the second file
file1 --> the first file

If the following command doesn't work:

fgrep -f file1 file2

use this:

awk -F, 'NR==FNR{x[$1];next}$1 in x' file1 file2

Use nawk or /usr/xpg4/bin/awk on Solaris.