pattern search and count

i want to search a word in a file and find the count of occurences even if pattern occures twice in a same line.

for example file has the following content.

yes no no nooo yees
no yes

if I search for "no" it should give count as 4

Pls help.
Thanks

grep -o no file | wc -l

Thanks era,
but I use ksh, and it gives the error
"grep: Not a recognized flag: o"

Actually grep is giving that error, the shell doesn't know what flags grep knows.

If you are on Solaris or HPUX, maybe you can find an XPG4 version of grep on your system?

Im using IBM AIX

In fact, it looks like grep -o is not actually supported by XPG4 anyway ...

How about this then?

perl -nle '++$c while (m/no/g); END { print $c }' file

Ya its working perfectly and in man pages also there is no option -o, may be it is no supported.
Thanks a lot era, but cant we do this with unix command?

Perl is a Unix command?

Is sed okay?

sed -e 's/no/\
no\
/g' | fgrep -xc no

You might have to wiggle with sed to get newlines into the replacement pattern; the above syntax works on Linux.

ya, It is working...., thank you..!!!

nawk '{
n=gsub(/no/,"no",$0)
s=s+n
}
END{
print s
}' filename