There are many errors in your script. First attempt?
Here is a working version:
for i in $(cat pattern.txt)
j=$(grep -c "$i" file1)
if [ $j -ne 0 ]
echo $i >> matches.txt
Basically you have to use command substitution
to put the result of grep into the j variable: the syntax uses backticks ` (not single quotes as in your code) or even better:
Then pay attention to the spaces inside the if/then expression: they are required to separate the square brackets from the expression. Check the differences with your version for other issues and feel free to ask if something is still not clear.