WAP Compare Two Given Files,If The Contents Are Same Remove Second One Gain Infiniti

WAP Compare Two Given Files,If The Contents Are Same Remove Second One


firstFile=$1
secondFile=$2

cmp $firstFile $secondFile | grep -q differ

if [ $? == 1 ]
then
    rm -rf $secondFile;
    echo "$firstFile and $secondFile are same !"
    echo "Deleted $secondFile"
else
    echo "$firstFile and $secondFile are different !"
fi


OUTPUT:-

#!/bin/bash
#root@slack-linunx:~/scripts# cat testFile
#ABCD EFGH
#IJKL MNOP
#root@slack-linunx:~/scripts# cat testFile2
#ABCD EFGH
#IJKL MNOP
#root@slack-linunx:~/scripts# ./rmDiffFile.sh testFile testFile2
#testFile and testFile2 are same !
#Deleted testFile2
#root@slack-linunx:~/scripts#

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 

Design By Manish and Ranjan