I am writing a file comparison utility and using the cmp command to compare 2file. But I need command that will compare 2 files and if the files are identical expect for differences in white spaces, then it should ignore those spaces and consider the two files equal. Is there a way to achieve this via shell scripting or a unix command?
---------- Post updated at 01:52 PM ---------- Previous update was at 01:34 PM ----------
If all you want to know is whether the files are different or not, test the reply code from "diff -w". The reply is "0" if they are identical after ignoring white space. The reply is "1" if they are different after ignoring white space.
diff -w file1 file2 >/dev/null;REPLY=$?
if [ ${REPLY} -eq 0 ]
then
echo "Files are identical"
else
echo "Files are different"
fi
That too doesnt seem to work, it gives a messages files are identical althrough the size of both the files are different Please help is there any other way I can exclude the whitespaces??
The difference in size is due to white spaces in one of the file. There are extra lines added as white spaces but the code in both the file is exactly the same.