Issue with Comparing 2 files using SDIFF

558 views Asked by At

I have a module that I am currently stuck on. I would like to seek your assistance on this.

Let say I have a file with the following entries:

ABC 123 ... <-- 1st occurence base on column 1 value

CDE 456 ...

DEF 234 ...

ABC 234 ... <-- 2nd occurence base on column 1 value

and another file with this entries:

           <-- missing 1st occurence

CDE 234 ...

DEF 456 ...

ABC 346 ... <-- 2nd occurence base on column 1 value

Currently I need to compare both files and came up with an output saying that the 2st occurence is missing from the 2nd file. The first stage of the task is completed ( I am not sure if this is the right way to handle this ). First, I sorted out both files base on the values of column 1. Then I use "sdiff -s" to compare both sorted files. The limitation I've got with this approach is that the "sorted file" only contains data column 1.

For example:

ABC

ABC

CDE

DEF

This gave me the desired outcome. But the problem is, I could not figure out which occurence of ABC was missing from the second file. If I use "grep" on the first file base on the result of "sdiff -s", it will give me 2 values.

Can someone shed some insight on this?

Thanks.

1

There are 1 answers

0
anishsane On

How about

sdiff -s <(cut -d' ' -f1 file1) <(cut -d' ' -f1 file2)

(I guess, you need bash version 4+ for process redirection to work)