I am trying to merge two csv files using AWK. If the 1st column in file 1 matches the 1st column in file 2 I want to change file1's 3rd column to the value of file2's 2nd column. If there is no match, make no changes and move on to next row.
file1.csv
alice,soccer,24
bob,baseball,21
jessica,swimming,22
mike,running,20
file2.csv
alice,5
jessica,9
desired output:
alice,soccer,5
bob,baseball,21
jessica,swimming,9
mike,running,20
My code so far:
#!/bin/bash
awk -F"," 'BEGIN{OFS=","}
{ if (NR==NFR){
array[$1]=$1;
}
if ( $1 in array ){
$3=array[$2]
}
print
}' file2.csv file1.csv
array[$1]=$1
butarray[$1]=$2
-- that will actually capture the data in file2