Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Location
    Virginia
    Posts
    2

    Red face Unanswered: 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.

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    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


    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.

  3. #3
    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

  4. #4
    Join Date
    Jun 2003
    Location
    Hamburg, Germany
    Posts
    38
    Why not use the sort command on both files and then use the comm command?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •