1824976 Members
3267 Online
109678 Solutions
New Discussion юеВ

Re: diff command

 
SOLVED
Go to solution
panchpan
Regular Advisor

diff command

Hello.
Can we use diff command or any other to find differnce in two files which shows only difference and no '<' '>' or any other output.

Thanks
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor
Solution

Re: diff command

Hi:

If you want to 'diff' two files but discard any output and only evaluate whether or not the files differ, do:

# diff file1 file2 > /dev/null 2>&1 && echo "no difference" || echo "files differ!"

This simply tests the return value from 'diff'. A zero value means no differences.

Regards!

...JRF...
Wouter Jagers
Honored Contributor

Re: diff command

Well, somehow you should know if the 'extra' or 'missing' data is in file 1 or file 2, no ?

Maybe the 'cmp' command can be useful to you, depending on what you want to do. Using the -s option to cmp you should not get -any- output, and the return code will tell you whether or not the files are identical.

Cheers
an engineer's aim in a discussion is not to persuade, but to clarify.
Georg Tresselt
Honored Contributor

Re: diff command

Well, what about appending something like "| sed 's/\>//'" to your diff command line?
http://www.tresselt.eu
panchpan
Regular Advisor

Re: diff command

THANKS