How to find a word in a directory which contains many files?
i just want to count how many such words are present in all the files?
This is the code which i tried for a single file
echo "Enter the file name:"
read file
echo "Enter the word to search:"
read word
if [ -f $file ]
then
echo "The count is :"
grep -o $word $file | wc -l
else
echo "The word doesn't exist"
fi
i just need to print the counts for each file in a directory
how can i execute this using for loop?
in my case there is no subdirectory
---------- Post updated at 07:46 PM ---------- Previous update was at 07:43 PM ----------
echo "Enter the word to search:"
read word
for (( i=1; i<=10; i++ ))
do
if [ -f $file ]
then
count=grep -o $word $file | wc -l
echo "$i '/t' $file '/t' $count "
else
echo "The word doesn't exist"
fi
done