Wednesday, 20 February 2013

To write a shell script that accepts a list of file names as its arguments,counts and reports the occurrence of each word that is present in the first argument file on other argument files.

Program:To write a shell script that accepts a list of file names as its arguments,counts
         and reports the occurrence of each word that is present in the first argument
         file on other argument files.

clear
echo " Enter the number of files::"
read n
echo "Enter the "n" files ::"
read fn
set $fn
for i in `cat $1`
do
echo -e " word = $i"
echo -e "------------"
grep -c "$i" $*
echo -e "------------"
done




/*-------------------------INPUT/OUTPUT------------


Enter the number of files::
2
Enter the n files ::
ex1.txt ex2.txt


word = this
------------
ex1.txt:1
ex2.txt:0
------------
 word = is
------------
ex1.txt:1
ex2.txt:0
------------
 word = linux
------------
ex1.txt:1
ex2.txt:1
------------
-bash-3.2$

---------------------------------------------------------*/

4 comments: