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

I have a requirement to match column 4 (Grade) from File1 csv with column 1  (Grade) of File2 , if. If it matches then, replace column 4  (Grade) of File1 csv with Column2column2 (Marks) of File2. if not matchesIf it doesn't match, then leave previousthe 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"

"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"

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

Expected Outputoutput:

"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"

"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 howan awk command should be for this Output output? 
Looking ahead for your response.

I have a requirement to match column 4 (Grade) from File1 csv with column 1(Grade) of File2 , if matches then replace column 4(Grade) of File1 csv with Column2 (Marks) of File2. if not matches then leave previous 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 how awk command should be for this Output ? Looking ahead for your response

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.

Source Link

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 csv with column 1(Grade) of File2 , if matches then replace column 4(Grade) of File1 csv with Column2 (Marks) of File2. if not matches then leave previous 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 how awk command should be for this Output ? Looking ahead for your response