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

Commands:
tr: The tr command can be used for to translate the characters that means the given string is replaced with the replacement string.

Syntax: Tr [original string] [replacement string]

grep: The grep command can be used for to search the regular pattern on given file.
Syntax: grep [ pattern ] file name

				
					if [ $# -eq 0 ]
 then 

echo "no arguments" 

else

 tr " " "

" < $1 > temp 

shift for i in $*

 do

 tr " " "

" < $i > temp1 

y=`wc -l < temp`

 j=1 

while [ $j -le $y ] 

do 

x=`head -n $j temp | tail -1` 

c=`grep -c "$x" temp1`

echo $x $c

 j=`expr $j 1`

done 

done 

fi
Facebook
				
			

Leave a Reply