Comparing two csv file fields using awk script

Hi All,

I want to remove the rows from File1.csv by comparing the columns/fields in the File2.csv. I only need the records whose first column is same and the second column is different for the same record in both files.Here is an example on what I need.

File1.csv:

RAJAK|ACTIVE|1
VIJAY|ACTIVE|2
TAHA|ACTIVE|3

File2.csv:

VIJAY|INACTIVE
TAHA|ACTIVE

Output: File1.csv

VIJAY|ACTIVE|2

Above scenario I need to delete the records if col1 of File1=col2 of File2 and col1 of File1 not equal to col2 of File2 the output should be File1 after removing the unwanted records.

I was using the script like this but no use:(sorry I'm new to shell scripting)

awk -F"|" 'FNR==NR{++a[$1,$2];next} (a[$1])!(a[$2])' File2.csv File1.csv

Can you please help me out in preparing awk scripting for above.

Thanks in Advance.

$ awk 'NR==FNR{a[$1]=$2;next}{if ($1 in a && a[$1] != $2)print;}' FS="|" File2 File1  
VIJAY|ACTIVE|2

Guru.

1 Like

Thank you so much Guruprasad. It works. Appreciate the quick response.

Thank you once again.