compare files and then remove some lines

Hi everyone

I have a dilemma and I'm hoping someone has an answer for me.

I have two files:

# cat masterfile
line3
line4
line5
line6
line7
# cat tempfile
line1
line2
line3
line4

I want to compare tempfile with masterfile.

If there are any rows in tempfile that are NOT present in masterfile (line1 and line2 in this example) I want to remove them from tempfile.

So the end result should be:

# cat tempfile
line3
line4

Can anyone advise me on how to accomplish this?

Many thanks

P.S. I'm using Solaris 10

Hi

grep -f tempfile masterfile > temp1 && mv -f temp1 tempfile

Guru.

Does ur file have only one row with n values ... or it will have more sentences ?

Thanks Guru, but the -f switch doesn't work on Solaris.

This is an example of the lines that are in my files:

FMDP0001_MSH11193_ATD-AAE-F6R-CB_100803_234702_book-1_page-1.png
FMDP0001_MSH11193_ATD-AAE-F6R-CB_100803_234702_book-1_page-1.xml
FMDP0001_MSH13299_ATD-AAE-F6R-CB_100803_230354_book-1_page-1.png
FMDP0001_MSH13299_ATD-AAE-F6R-CB_100803_230354_book-1_page-1.xml

---------- Post updated at 11:25 AM ---------- Previous update was at 11:07 AM ----------

Correction:

There are two version of grep on Solaris 10

/usr/bin/grep
/usr/xpg4/bin/grep

The -f switch works on the second one.

Thank you for the solution.