I am trying to compare 2 Tab Delimited files and output differences with Column Header and No Primary Key in File.
I am very near to it but what I am facing the problem is the Snippet i have reached into is working if and only if it has a Primary Key-
awk '
NR==1 {
for (i=1; i<=NF; i++)
header[i] = $i
}
NR==FNR {
for (i=1; i<=NF; i++) {
A[i,NR] = $i
}
next
}
{
for (i=1; i<=NF; i++)
if (A[i,FNR] != $i)
print "ID#-" $1 ": " header[i] "- " ARGV[1] " value= ", A[i,FNR]" / " ARGV[2] " value= "$i
}' t1.csv t2.csv
Can anyone please help me how to achive it
- When I don't have any primary key in it
- When Number of Rows are not same and one file has missing records
t1.csv
Month ClientSegment ClientType IssuerClientSegment NetworkID VD
2020-12 COMMUNITY EXEMPT COMMUNITY 0 OTHER
2020-12 COMMUNITY EXEMPT COMMUNITY 2 OTHER
2020-12 COMMUNITY EXEMPT COMMUNITY 5 OTHER
t2.csv
Month ClientSegment ClientType IssuerClientSegment NetworkID VD
2020-12 COMMUNITY EXEMPT COMMUNITY 0 OTHER
2020-12 COMMUNITY EXEMPT COMMUNITY 2 OTHER1
2020-13 COMMUNITY EXEMPT COMMUNITY 2 PUSH
2020-13 COMMUNITY EXEMPT COMMUNITY 3 OTHER
Expecting Output Like:
Row 2, Column: VD- t1.csv value= OTHER / t2.csv value= OTHER1
Missing in t2.csv
Month Client Segment Client Type Issuer Client Segment Network ID VD
2020-12 COMMUNITY EXEMPT COMMUNITY 5 OTHER
Missing in t1.csv
Month Client Segment Client Type Issuer Client Segment Network ID VD
2020-13 COMMUNITY EXEMPT COMMUNITY 2 PUSH
2020-13 COMMUNITY EXEMPT COMMUNITY 3 OTHER