Results 1 to 6 of 6

Thread: How to find entries present in one file but not in another?

  1. #1
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,470
    Distro
    Lubuntu 14.04 Trusty Tahr

    How to find entries present in one file but not in another?

    I have two files: A and B which are lists with one string per line and both have been sorted in the same way and do not contain duplicates.

    Is there a command line way to make a third file, C, containing entries present only in A.

  2. #2
    Join Date
    Aug 2006
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: How to find entries present in one file but not in another?

    That would be diff. See man diff for more info.

  3. #3
    Join Date
    Apr 2012
    Beans
    5,050

    Re: How to find entries present in one file but not in another?

    How about grep -f?

    Code:
    fgrep -vf B A > C

  4. #4
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,470
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: How to find entries present in one file but not in another?


  5. #5
    Join Date
    Dec 2007
    Location
    Bombay
    Beans
    5,470
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: How to find entries present in one file but not in another?

    Quote Originally Posted by steeldriver View Post
    How about grep -f?

    Code:
    fgrep -vf B A > C
    Actually, this ^^^ works. Thanks!

  6. #6
    Join Date
    Apr 2012
    Beans
    5,050

    Re: How to find entries present in one file but not in another?

    I didn't know about comm, but it looks like that would be more efficient for files that are already sorted

    Code:
    comm -23 A B > C

Bookmarks

Posting Permissions

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