Compare two file and print same line

i want to compare two file and print same line

file1
12345 a
23456 a
45678 a
45679 a

file2
23456 a
34567 a
45679 a

output
23456 a
45679 a

any one can help me? Thank you

try:

grep -f file1 file2

Try this one.

comm -12 file1 file2

Can done by script ? as the file are too big...

this would be your simplest solution:

why do it by script? are you talking about writing the solution into a file instead of displaying the output on the screen?

if so this should work:

grep -f file1 file2 > FILE

gawk 'NR==FNR{a[$0]=$0 ; next} a[$0]' file1 file2

Because it shown error

PCCG1[admin]# grep -f file1 file2
grep: Regular expression too big

grep shows error...

but what about comm ?! -- as suggested earlier

comm -12 file1 file2