The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk - comparing files dbrundrett Shell Programming and Scripting 4 08-22-2008 07:23 AM
Comparing two files superstar003 Forum Support Area for Unregistered Users & Account Problems 1 05-08-2008 12:34 AM
Comparing two files.. padarthy Shell Programming and Scripting 1 08-29-2007 05:01 AM
Comparing two files... paqman Shell Programming and Scripting 12 08-08-2007 12:45 AM
comparing shadow files with real files terrym UNIX for Advanced & Expert Users 4 02-08-2007 11:38 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-08-2007
Registered User
 

Join Date: Mar 2007
Posts: 19
comparing two files

Hi everyone,
I have two files, and i want to detect the diffrent lines in these files. I tried to use the comm and diff commands, but I got that they are only comparing the lines in the same sequence number.
forexample: file1 file2
cat dog
dog elephant
elephant snake

I want to detect only cat in file1 and snake in file2, but the comm and diff commands will detect all the entries, as dog for example, is in diffrent lines.
Thanks for help.
Reply With Quote
Forum Sponsor
  #2  
Old 06-08-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Sort the files if it is not sorted
Code:
comm -3 file1 file2
Reply With Quote
  #3  
Old 06-09-2007
Registered User
 

Join Date: Mar 2007
Posts: 19
sorting the files will not work in all cases, if I sorted file1 and file2, nothing will change.
Reply With Quote
  #4  
Old 06-09-2007
solfreak's Avatar
Registered User
 

Join Date: Jun 2007
Posts: 35
A quick hack:

diff file1 file2 | egrep '^< |> ' | cut -c3- | uniq -u
Reply With Quote
  #5  
Old 06-09-2007
Registered User
 

Join Date: Mar 2007
Posts: 19
Thanks Solfreak for your reply, but can you explain it for me, please.
Thanks
Reply With Quote
  #6  
Old 06-09-2007
solfreak's Avatar
Registered User
 

Join Date: Jun 2007
Posts: 35
Does it work ?
Reply With Quote
  #7  
Old 06-10-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Quote:
Originally Posted by marwan
sorting the files will not work in all cases, if I sorted file1 and file2, nothing will change.
Did you get the expected output?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0