Quote:
Originally Posted by cfajohnson
Code:
tr -cs 'A-Za-z' '\n' < FILE | grep -c "WORD"
|
This solution does not work.
Here is a sample file:
Code:
a aa aaa
aaa aa a
aaa aa a aaa aa a aaa
Here is one test:
Code:
tr -cs 'A-Za-z' '\n' < FILE | grep -c "aaa"
It gives the total of words as '3', when the answer is '5'.
Here is another possible solution for those who want to use shell script:
Code:
#!/bin/ksh
typeset -i mCnt=0
mWord='aaa'
for mEach in `cat input_file`
do
if [ "${mEach}" = "${mWord}" ]; then
mCnt=${mCnt}+1
fi
done
echo 'Total words for '${mWord}' = '${mCnt}