PDA

View Full Version : Easy File Compare question


Bignose
04-23-03, 12:04
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.

sathyaram_s
04-23-03, 12:48
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


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.

Bignose
04-23-03, 14:12
Sathyaram,

Many Thanks for that. Helped me out of a large hole

AdiHH
06-11-03, 07:15
Why not use the sort command on both files and then use the comm command?