specified word count

hi iam trying to do a specified word count on file
called text
i have a few ideas but don't get the result i want
do any one have a idea
please help

i have this at the moment

cat text
echo "Please enter the word you are looking for:"
read string
echo "the word < $string > occurs in the following lines of file < $1 >:"
grep $string $1
echo
echo "press ENTER to continue"
read key

if you are okay with Perl, check my post in this thread

iam to not use perl

Why ? Dont you have perl installed ?

Try this.

Save this script in some file.give first argument as filename and second argument as word you want to search.

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"

No homework questions on the Forums....

#!/bin/ksh
# $1 = input file $2=word to search for
tr -s ' ' '\n' < $1 | grep -c "$2"