How to take out multiple matches in file2 using file1 as a reference?

Hi guys,

As the title, I want to take out the lines in file2 if the TCONS_* matches that in file1. Then put the lines in a file3. The TCONS numbers ranges from TCONS_00000024 to TCONS_00381684. Those numbers are continuous in file2, not in file1. Below is just some lines of file1 and file2

File1:

TCONS_00000284        
TCONS_00198804
TCONS_00198826
TCONS_00067013

File2:

chr1   exon    65233257        65233407     transcript_id "TCONS_00000284"; 
chr1   exon    65236893        65237073     transcript_id "TCONS_00000284"; 
chr1   exon    65233257        65233407     transcript_id "TCONS_00000285";
chr1   exon    65236893        65237073     transcript_id "TCONS_00000285"; 

Thanks very much!

Take a look at the command

grep -f

Thanks Joey. But I need to compare all the transcript id in file1 and file2, so I need to use some loops. I'm quite new to perl, could you please give me more details about the codes?

Why perl? grep -f is what you want

# this makes file3
grep -f file1 file2 > file3
# selectively lose lines in file2 that are in file1
grep -f -v file2 file2 > tmpfile
# read and check that tmpfile is correct.  then
mv tmpfile file2

You don't need perl or loops, joeyg gave you great advice.

Does the "grep -vf file1 file2>tmpfile" mean move the the lines in file2 that are not in file1 to tmpfile? I don't need those that don't match.
What does the the first line mean?
Thanks very much.