Compare Values in a Delimited Text file

Hi,

How do I compare two columns within a text file

If 2nd column values are same then I want to know 3rd column number matches or not

Example:

Prod  Stag1 1234.79
Prod  Stag2 1234.79 20
Prod  Stag3 1234.79 30
Prod  Stag4 1234.79
UAT  Stag1  1243.56
UAT  Stag2  1243.56 20
UAT  Stag3  1243.56 30
UAT  Stag4  1243.56

Expected Output

Prod & UAT are not matching for Stag1 
awk '!($2 in f2) { f2[$2]=$3; f1[$2]=$1;next} f2[$1] != $3{ print f1[$2] " & " $1 " are not matching for " $2}' myFile
1 Like

Thanks vgersh. Updated the input data.

I don't get it. You give us a problem and vgersh99 gives you code that produces the output you requested.

Instead of telling us what is wrong with the code vgersh99 suggested, you add three more pairs of non-matching data to your sample input and expect the output to remain unchanged (thereby making sure that the code vgersh99 suggested no longer works).

Will you please provide a clear explanation as to what the code is really supposed to do so that we might have a chance of understanding why the three added non-matching pairs of input lines should not produce any output?

1 Like