The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 6 01-18-2009 10:51 PM
Comparing two files superstar003 Forum Support Area for Unregistered Users & Account Problems 1 05-08-2008 03:34 AM
Comparing two files.. padarthy Shell Programming and Scripting 1 08-29-2007 08:01 AM
Comparing two files... paqman Shell Programming and Scripting 12 08-08-2007 03:45 AM
comparing shadow files with real files terrym UNIX for Advanced & Expert Users 4 02-09-2007 02:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-08-2007
marwan marwan is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 20
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.
  #2 (permalink)  
Old 06-08-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Sort the files if it is not sorted
Code:
comm -3 file1 file2
  #3 (permalink)  
Old 06-09-2007
marwan marwan is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 20
sorting the files will not work in all cases, if I sorted file1 and file2, nothing will change.
  #4 (permalink)  
Old 06-09-2007
solfreak's Avatar
solfreak solfreak is offline
Registered User
  
 

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

diff file1 file2 | egrep '^< |> ' | cut -c3- | uniq -u
  #5 (permalink)  
Old 06-09-2007
marwan marwan is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 20
Thanks Solfreak for your reply, but can you explain it for me, please.
Thanks
  #6 (permalink)  
Old 06-09-2007
solfreak's Avatar
solfreak solfreak is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 35
Does it work ?
  #7 (permalink)  
Old 06-11-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
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?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0