Monday, 9 April 2018

Shell script to remove multiple copies of the same file content

#Script to compare contents of two files
echo "Enter two file name"
read f1 f2
d=`cmp $f1 $f2`
if [ -z "$d" ]
then
echo "Both file contents are same"
echo "File $f2 is deleted"
rm $f2
else
echo "Both are different"
fi





OUTPUT
Safi>sh cmpdel.sh
Enter two file name
ff file
Both are different

Safi>sh cmpdel.sh
Enter two file name
ff ff
Both file contents are same
File ff is deleted

No comments:

Post a Comment