A shell script to accept a filename and a word as a command line argument and count the occurrence of given word in given file.

if [ $# -ge 2 ]

then

echo “Command line argument is valid”

else

echo “you have to enter tow argument”

fi

count=grep -c "$2" $1

echo “Occurance of the word $s2 if file $1 is $count”

OUTPUT::

Command line argument is valid

Occurance of the word  if file s.txt is 1

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.