count occurences of specific character in the file

For counting the occurences of specific character in the file
I am issuing the command
grep -o 'character' filename | wc -w
It works in other shells but not in HP-UX as there is no option -o for grep.
What do I do now?

Forgot to mention I have an alternate solution
cat filename | tr -d '\n' | tr -s '"' '\n' | wc -l
But I am looking for a grep solution
Is it possible to make some changes in grep command here?

I use this, not necessarily the most efficient..

# charcnt count given char or chars in a file
# filename $1
# character or string $2
cnt=`grep "$2" $1 |
     awk -v CH="$2" '
          BEGIN {cnt =0}
          { while (y=index($0,CH))
            { cnt++
              y++
              $0=substr($0,y);
            }
          }
          END {print cnt }'`
echo "$2" "occurs $cnt times"

awk '{c+=gsub(s,s)}END{print c}' s='character' filename

I am experiencing problem while executing the command :

awk '{c+=gsub(s,s)}END{print c}' s='character' filename

for character '\307'. could you please tell how to handle these type of characters.

try setting locale to univ.utf8

Seems to work...

$ printf "123\307abc" > file1
$ awk '{c+=gsub(s,s)}END{print c}' s='\307' file1
1

Or try...

$ tr -dc '\307' < file1 | wc -c
1

Thanks a lot. it is working fine.

This sort of thing should also work:
sed -e 's/[^myChar]//g' myFile | wc -c
where myChar is the character you are searching for and myFile is the file you are searching in.

This is really old.

you could also try this example looking to count character zeroes:

 tr -dc '0' < somefile |  wc -c