Awk compare two files

Hi guys,

I have 2 files:

File1

ABC|2203|115.50
ABC|2288|328.12
ABC|2289|611.09
ABC|2290|698
DEF|1513|721.3
DEF|1514|40
DEF|1515|5

File2

ABC|2288|328.12
ABC|2289|666.08
ABC|2290|698.00
DEF|1513|721.30
DEF|1514|40.00
DEF|1515|5.00

I want to use awk to obtain

A file with $0 when $3 was different in amount
A file with records of File1 not included in File2
A file with records of File2 not included in File1
If is possible (I tried with ed<<) put the decimals correctly

Thanks!!

$ cat xcomm.awk

BEGIN { FS="|"; OFS="|" }

F != FILENAME { FNUM++; F=FILENAME }

$1 SUBSEP $2 in COL {
        if(FCOL[$1, $2, COL[$1,$2]] != $0)
        {
                print FCOL[$1,$2, COL[$1,$2]] >"diff";
                print > "diff";
        }
}

{       COL[$1,$2]=FNUM; FCOL[$1, $2, FNUM]=$0  }

END {
        for(X in COL)   for(N=1; N<=FNUM; N++)
        {
                if(! (X SUBSEP N in FCOL))
                        print FCOL[X SUBSEP COL[X]] >"missing-"N
        }
}

$ awk -f xcomm.awk data1 data2

$ cat diff

ABC|2289|611.09
ABC|2289|666.08
ABC|2290|698
ABC|2290|698.00
DEF|1513|721.3
DEF|1513|721.30
DEF|1514|40
DEF|1514|40.00
DEF|1515|5
DEF|1515|5.00

$ cat missing-2

ABC|2203|115.50

$
1 Like

Hi Corona,

Thank you for your response.

I tried your awk script, but awk send me this error:

$ awk -f xcomm.awk File1 File2
awk: Internal software error in the tostring function on EMK�29412�2.
The input line number is 75359. The file is File2.
The source line number is 40.

I don't know why put an � character vs. | "pipeline"

Thank you again!!

Try nawk.