If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Easy File Compare question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-23-03, 11:04
Bignose Bignose is offline
Registered User
 
Join Date: Apr 2003
Location: Virginia
Posts: 2
Red face Easy File Compare question

New to this so please type any response slowly......

Dead easy question I suspect. I have two files. Both with a long, long list of names in them. What's a nice easy way to take each name in turn from list one and see if it appears in list 2. Then output all those that do appear in both lists into a third file.
I can see how to use grep (for instance) to see if A name appears in the second list, but there must be a way to automate things so I don't have to do

grep -i SmithJ Secondlist........
grep -i SmithN Secondlist...etc etc. Else I will be here until October......

The order of the names within the files are so completely different which I believe would make something like "diff" useless ......??

Many Thanks in advance for any help.
Reply With Quote
  #2 (permalink)  
Old 04-23-03, 11:48
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
Re: Easy File Compare question

I do not know about the performance, but you can do

cat file1 | grep -ffile2 > file3

This gets a list of all names in file1 which appear in file2 ...

HTH

Sathyaram


Quote:
Originally posted by Bignose
New to this so please type any response slowly......

Dead easy question I suspect. I have two files. Both with a long, long list of names in them. What's a nice easy way to take each name in turn from list one and see if it appears in list 2. Then output all those that do appear in both lists into a third file.
I can see how to use grep (for instance) to see if A name appears in the second list, but there must be a way to automate things so I don't have to do

grep -i SmithJ Secondlist........
grep -i SmithN Secondlist...etc etc. Else I will be here until October......

The order of the names within the files are so completely different which I believe would make something like "diff" useless ......??

Many Thanks in advance for any help.
Reply With Quote
  #3 (permalink)  
Old 04-23-03, 13:12
Bignose Bignose is offline
Registered User
 
Join Date: Apr 2003
Location: Virginia
Posts: 2
Smile Re: Easy File Compare question

Sathyaram,

Many Thanks for that. Helped me out of a large hole
Reply With Quote
  #4 (permalink)  
Old 06-11-03, 06:15
AdiHH AdiHH is offline
Registered User
 
Join Date: Jun 2003
Location: Hamburg, Germany
Posts: 38
Why not use the sort command on both files and then use the comm command?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On