Select the exact matching contents using grep

Hi everyone I've two files..
The contents of file1 are as shown below

4
5
12
13
36
37
45
46
47

The contents of file2 are as shown below

21 hello
13 world
4 Hi
36 how
44 are
5 you
56 ?

If I use

grep -f file1 file2

I get the following output

13 world
4 Hi
44 are
5 you
56 ?

I want output as shown below

13 world
4 Hi
5 you

I've to match the exact line number at the beginning of the line!!
How can I do it??
I need to write a shell script for that..

try this...

grep -Fw file1 file2
awk 'FNR==NR{a[$1]=1} NR>FNR{if($1 in a)print $0}' f1 f2
nawk 'FNR==NR{f1[$0];next} $1 in f1' file1 file2

thanks for the reply
but am not getting any output by using grep -Fw command..:frowning:

---------- Post updated at 02:49 PM ---------- Previous update was at 02:42 PM ----------

thank u..its working using awk command..:slight_smile:

Using solaris you can try this syntax hope this should work...

/usr/xpg4/bin/grep  -w -f file1 file2

Thanks
Sha