I have 2 files,
file1 ->
abc=3
abc=3
dfg=6
ggg=7
file2 ->
abc=3
dfg=4
sdf=9
I want the output in file3 as,
File2,File1,Result
abc=3,abc=3,Match
dfg=4,dfg=6,NoMatch
sdf=9,,NotPresent
,abc=3,Duplicate
I currently have a script,
grep -E 'abc|dfg|sdf' file1 >> file3
comm <( sort -n file2 ) <( sort -n file3 ) |awk -F$'\t' 'BEGIN { OFS="," } $3 { print $3, $3, "MATCH"; next } { print $1, $2, "NO MATCH" }' > final_result.txt
The output looks like,
abc=3,abc=3,MATCH
,abc=3,NO MATCH
dfg=4,,NO MATCH
,dfg=6,NO MATCH
sdf=9,,NO MATCH
The output displays a blank if the value in file2 does not match the value in file1. For example, the only difference between dfg=4,,NO MATCH and ,dfg=6,NO MATCH is that the value has changed from 4 to 6. I would like the output to be
dfg=4,dfg=6,NoMatch
instead of
dfg=4,,NO MATCH
,dfg=6,NO MATCH
And also,
abc=3
appears twice, but is displayed as
,abc=3,NO MATCH
I would like to have it as,
abc=3,,Duplicate
Any help is greatly appreciated.