Thursday, 29 March 2018

Shell scrit to check whether the two file contents are same


#Shell script to compare the contents of two files
echo "Enter file 1"
read file1
echo "Enter file 1"
read file2
val=`cmp $file1 $file2`
if [ -z "$val" ]
then
   echo "Files have same content"
   rm $file1
   echo "$file1 removed"
else
   echo "File contents are different"
fi



OUTPUT
csc@csc-SVE1513CYNB ~ $ sh same.sh
Enter file 1
file
Enter file 1
file
Files have same content
file removed

csc@csc-SVE1513CYNB ~ $ sh same.sh
Enter file 1
file2
Enter file 1
file3
File contents are different

No comments:

Post a Comment