awk script to count characters in file 1 in file 2

I need a scripting AWK to compare 2 files.

file 1 and 2 are list of keywords
1 is

a
b
c
d

2 is

aa
aaa
b
bb
ccc
d

I want the AWK script to give us the number of times every keyword in file 1 occurs in file 2.
output should be

a 2
b 2
c 1
d 1

Please use code tags as required by forum rules!

awk     'NR==FNR {TMP[$1];next}
                 {for (i in TMP) if (match ($0, i)) TMP++}
         END     {for (i in TMP) print i, TMP}
        ' file1 file2
a 2
b 2
c 1
d 1

Yes you need that, you should also post what have you tried so far with respect to the problem.

$ cat temp.sh
while read pattern; do
  echo -n "$pattern "
  grep -c $pattern file2
done < file1
$ ./temp.sh
a 2
b 2
c 1
d 1
f 0

I added additional "f" line to file1 for better test.

Take some care when using match ($0, i)
Not sure what the intention of this counting is, but if the code have a line like abb it would be counted both as a and as b

Thanks for all friends

I have a big text file that need to process.
As I know, awk is the best tool to process text file. That why I'm looking for someone help me. Because for a long time, about 5 years, I haven't use awk. So I cann't remember any more.

Hi. RudiC

I've done the test with your script. But I don't know why the result have 6 on the top of output results.
6
a 2
b 2
c 1
d 1

Can you explain to me? And how can I delete it in output result? Thanks

If you just want to delete the first line, "tail -n +2"

$ seq 3
1
2
3
$ seq 3 | tail -n +2
2
3

This is because you have an empty line in file1.