I've two files f1.txt
From,Key,Count
abc.org,hello,5
abc.com,hello world,2
def.com,hi there,1
efg.com,hello world,1
f2.txt
h1,hello world
h2,hi there
h3,hello
I want the output file like below
From,Key,Count
abc.org,h3,5
abc.com,h1,2
def.com,h2,1
efg.com,h1,1
where the second column of f1.txt is matched against second column of f2.txt and the value is replaced with second column of f2.txt in the output file, (unique part)
I tried using awk like below:
awk -F',' FNR==NR{a[$2]=$1;next} ($2 in a) {print $1,a[$1],$2}' f2 f1
But it is giving errors and not working as expected
what shall I modify in the awk command?
Update: @Inian That question is merging the two files based on a common field, I've asked for replacing a field based on a mapping from the second file.