How to compare two files using shells script.

This shells script can compare two files word by word. Normaly you can use diff command for compare two files, but I think this shell script good for your requrement. Here "mdp" and "agora" are the two files which I used to compare. You can change that file names.
check it out.

#!/bin/bash

#File no. one
FILE1=mdp

#File no. two
FILE2=agora

MINSIDE=`cat $FILE1`
AINSIDE=`cat $FILE2`
for i in $AINSIDE
do
for j in $MINSIDE
do
if [ "$i" = "$j" ];then
echo "$i -> $j [mached]"
fi
done

COMCOUNT=`grep -w -c "$i" $FILE1`
if [ $COMCOUNT -lt 1 ]; then
echo "$i [unmached]"
fi
done

Comments