removing duplicate records comparing 2 csv files

Hi All,

  I want to remove the rows from File1.csv by comparing a column/field in the File2.csv. If both columns matches then I want that row to be deleted from File1 using shell script\(awk\). Here is an example on what I need.

File1.csv:

RAJAK,ACTIVE,1
VIJAY,ACTIVE,2
TAHA,ACTIVE,3

File2.csv:

VIJAY
TAHA

Output:

RAJAK,ACTIVE,1

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

Can you please help me out in preparing a shell script for above.

Thanks in Advance.

Use grep with the -v and -f option. Check your man page.

Does the below command snippet serves your purpose ?

egrep -v $(cat file2.csv | tr '\n' '|' | sed 's/.$//') file1.csv

Hi codemaniac,

I tried the given code but it is giving the following error.
Error: grep: can't open |VIJAY

Actually I'm new to this shell/awk scripting. Is there any help using awk script will be very much helpful. 

Thank you.

Working with Franklin52's suggestion this is probably all you need:

grep -v -f file2.csv file1.csv >output-file

I note that in your sample, file2 isn't actually a comma separated list. If that is true, then the previous command will be fine. However, if file2 is indeed a comma separated list (as the name and your description implies) then you'll need to take a different approach.

Dear Rajak ,

Can you chechk if egrep is available in uour *NIX flavor ?

which egrep

I have tested the below commandline in my RHEL and DEBIAN box .

egrep -v $(cat file2.csv | tr '\n' '|' | sed 's/.$//') file1.csv

Otherwise Agama's approach is the easiest , and you can use that .

Dear Rajak ,

Can you chechk if egrep is available in uour *NIX flavor ?

which egrep

I have tested the below commandline in my RHEL and DEBIAN box .

egrep -v $(cat file2.csv | tr '\n' '|' | sed 's/.$//') file1.csv

Otherwise Agama's approach is the easiest , and you can use that .