File Comparison command but ignoring while spaces

Hello All,

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?

Please help.

Thanks in advance.

you might be better served by the diff command.

diff -b in particular should be close to where you need to be.

HTH

I have tried both diff -bew but none seem to serving the purpose..any other suggestions are eargerly awaited.

Or?
diff -w

---------- 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 :frowning: Please help is there any other way I can exclude the whitespaces??

This is at odds with your original requirement/question.

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.

We are not communicating. Do you want such files to be reported as different or not?