Showing posts with label count the occurrence of a word in a file. Show all posts
Showing posts with label count the occurrence of a word in a file. Show all posts

Friday 5 April 2019

Shell script that asks for a word and a file name and then tells how many lines contain that word.

echo "Enter word,filename";
 read word filename
n=`grep -c "$word" $filename`;
echo "The word [$word] in the $filename has occurred in $n lines";




OUTPUT
Safi>sh eb.sh
Enter word,filename
word eb.sh
The word word in the eb.sh has occured in 4 lines

Safi>sh eb.sh
Enter word,filename
for eb.sh
The word for in the eb.sh has occured in 0 lines