count a occurrence

I am looking to get a output of "2 apple found" from the awk command below.

black:34104 tomonorisoejima$ cat tomo 
apple apple
black:34104 tomonorisoejima$ awk '/apple/ {count++}END{print count " apple found"}' tomo 
1 apple found
black:34104 tomonorisoejima$

Hi! If grep can be use then try this:

grep apple tomo|wc -w

EDIT: my bad! ignore this suggestion as I tested this with sample file and gives erroneous output.

Hi

Thanks for the answer, but it returns a word count.
I should have given a different file content.

black:34104 tomonorisoejima$ cat tomo 
tomo apple apple

try this instead

grep -o apple tomo |wc -l

Oh my God, I never used this -o option.

I was going through awk manual now and this grep option is returning
exactly what I need!

Thanks yongitz, You made my day.

Tomo

Hi.

Create one file say tomo.awk, content is the following

/apple/{
      for(i=1;i<=NF;i++)
      {
            if($i=="apple")
                  count++
      }
}
END{
      print "Number of apples "count
}

execute the following command

awk -f tomo.awk tomo
(or)
cat tomo|awk -f tomo.awk

Let me know if you got successful.

Thanks,
Shahnaz.