Skip to main content
2 of 2
formatting, spelling, edited tags
Freddy
  • 26.3k
  • 1
  • 27
  • 64

How to compare column in two different csv file and replace column from another file

I have a requirement to match column 4 (Grade) from File1 with column 1 (Grade) of File2. If it matches, replace column 4 (Grade) of File1 with column2 (Marks) of File2. If it doesn't match, then leave the value of column 4 (Grade) as is.

File1

"RollNo","Name","Age","Grade","Class","Teacher" "1","Asha","7","A","1","David" "2","Mona","7","B","1","David" "3","Sonali","7","C","1","David" "4","Rani","7","D","1","David" "5","Raj","7","B","1","David" 

File2

"Grade","Marks" "A","90" "B","80" "C","70" 

Expected output:

"RollNo","Name","Age","Grade","Class","Teacher" "1","Asha","7","90","1","David" "2","Mona","7","80","1","David" "3","Sonali","7","70","1","David" "4","Rani","7","D","1","David" "5","Raj","7","80","1","David" 

Can you please help me with an awk command for this output?
Looking ahead for your response.