I've researched many similar Q&As but am still stuck on a solution.
I have 2 files.
File1
cow
aaaaa
brown
bbbbb
often
ccccc
farts
ddddd
File2
In File2, with 'space' as a delimiter, then col 1="brown" and col2="149,456,foo". Also, File1 and File2 are not in the same order (sort doesn't work here, I want to count on the matching key to make the replacement).
brown 149,456,foo
cow 192,231,bar
farts 81,2007,tip
often 427,541,top
I want to create File3
cow 192,231,bar
aaaaa
brown 149,456,foo
bbbbb
often 427,541,top
ccccc
farts 81,2007,tip
ddddd
In other words, note column1-in-File2 (brown) and search for it in File1. When that match is found in File1, replace the match with the entire line of corresponding File2 (brown 149,456,foo).
I've tried this:
$ awk 'NR==FNR{a[NR]=$0;next}{$6=a[FNR]}1' file2 file1
But the results seem to take every row1 and then prints it next to with row1 from the other file, there's no match/replace involved.
brown brown 149,456,foo
aaaa cow 192,231,bar
cow farts 81,2007,tip
bbbbb often 427,541,top
farts
ccccc
often
ddddd
I'd like to use awk or sed. Much thanks in advance for any suggestions!