Find the answer to your Linux question:
Results 1 to 5 of 5
Hi Everyone! I am running into another problem that I would like some help on. I want to compare 2 columns from 2 different files and then report what was ...
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75

    compare 2 columns from 2 different files

    Hi Everyone!

    I am running into another problem that I would like some help on.

    I want to compare 2 columns from 2 different files and then report what was not found in file1 but was found in file2 to be reported to a 3rd file.

    File 1
    Code:
    ACCT00600002    DESKTOP1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN   Friday TRT1
    ACCT00600002    DESKTOP1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN   Monday TRT1
    ACCT00600002    DESKTOP1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN   Saturday TRT1
    File 2
    Code:
    ACCT00600002    DESKTOP1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN
    ACCT00600002    DESKTOP1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN
    ACCT00600002    DESKTOP1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN
    ACCT00600003    SERVER1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN
    File 3 (Desired Result)
    Code:
    ACCT00600003    SERVER1\BACKUP OF FILES ON C$,SYSTEM STATE AND SERVICES DATABASE\ADMIN
    File #2 does not contain a day or a TRT vaule. That is normal. I am trying to find out what lines are not present based on Column 1 and Column 2 and have it report back those differences in the 3rd file.

    Also is there a way to do the opposite. Such as if it is not found in file2 delete it out of file1?

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    what have you got so far?

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Quote Originally Posted by ghostdog74 View Post
    what have you got so far?
    I have tried this. But I think I have messed something up. It continues to brint every difference between the lines including what is in column 3 which is not what I want.
    Code:
    awk -F"\t" 'NR==FNR{++a[$1, $2];next}!a[$1, $2]' file1 file2 > file3
    As far as the removal from file1 if it does not exist in file2 I have not yet started to work on it.

  4. #4

  5. #5
    Just Joined!
    Join Date
    Oct 2007
    Location
    Houston
    Posts
    75
    Quote Originally Posted by ghostdog74 View Post
    remove -F"\t"
    Ah. I thought I needed that to tell awk they were tab seperated. Neat it worked.

    Now how would I got about removing the lines found in one file but not in the other?

Posting Permissions

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