Connecting Tech Pros Worldwide Forums | Help | Site Map

How do i Get return value (0/1) after comparing the two Files using 'cmp' Command ??

Member
 
Join Date: Nov 2008
Posts: 35
#1: Jan 7 '09
Hi Bytes..

In Linux, How can i get return value of comparing two files using the command cmp in the prompt.. when i was tried, it shows only output of unmatched lines(differ line )/ shows nothing if two file are same. please do help..

Thanks.

ashitpro's Avatar
Expert
 
Join Date: Aug 2007
Posts: 390
#2: Jan 7 '09

re: How do i Get return value (0/1) after comparing the two Files using 'cmp' Command ??


This should work for you...
Expand|Select|Wrap|Line Numbers
  1. if cmp a1.txt b1.txt > /dev/null
  2. then
  3.         echo "Files are same..."
  4. else
  5.         echo "Files are different..."
  6. fi
  7.  
Reply