Count Specific Letters and Words

Can anyone give me an idea how to make a shell script that can count the number of sentences, or a specific word eg. 'and' or a specific letter 'e'??? Pls give me and idea. I'm not very expereinced in UNIX yet. Thx.

/-----------------------------/
The following awk script count the number of words WORD in the input_file.
It assumes that the word is delimited by non alphabetic letters.

awk '
{ count += gsub(/(^|[^[:alpha:]])WORD([^[:alpha:]]|$)/,"_x_") }
END { print count }
' input_file

/-----------------------------/
WORD=the
file:
the the the other
then bathe
the the
count=3?

/-----------------------------/
to continue obfuscating:
perl -e '$word=shift;$count=0;while (<>){$count += s/\b$word\b//g;}print "$count\n";' WORD file

/-----------------------------/
Exact....
New version:

awk '
{
??while ((c = sub(/(^|[^[:alpha:]])the([^[:alpha:]]|$)/,"_x_")) > 0)
???? count += c;
}
END { print count }
' input file

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.