Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hallo,
We want to compare two files. The first two fields are key values.
Example:file 1
------
A; 1234, 12
B; 4435; 24
C; 7777; 50file 2
------
A; 1234, 32
B; 5435; 24
C; 7777; 50
D; 8888; 50Result
------
A; 1234; 12; Updated 32
B; 5435; 24; New in F1
D; 8888; 50; New in F2
When the first two fields are the same but the third value differs, this should be marked as update. If first two fields are not present in second file this shoud be marked as new in File 1 (vise versa).This problem can be solved in AWK but I am not familiar with this tool.
King regards
Hetwich

It might be possible to do this with AWK, but your description is incomplete. Are the field separators always ; ? I see a , in there too, which makes it difficult to use AWK's field separator. Are there blanks between each field, which could be used as the field separator?
If D;8888;50 is "new in F2", why isn't B;5435;24 also "new in F2" (and B;4435;24 "new in F1")? Your results don't seem to match your description. I only have experience doing fairly simple stuff in AWK, so I don't think I could get this thing working in AWK.
As cup suggested, "diff" might be the place to start. It will ignore unchanged lines, and flag lines inserted or deleted going from one file to the other. Then you post-process the diff file to determine whether a paired insertion/deletion meets the criteria for "updated" rather than "new in X". AWK might be able to handle that, or a Q&D C program might be easier.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |