I am trying to approximate vlookup from excel.
I have two files.
file #1 - list.txt:
green
purple
orange
file #2 - reads.txt:
blue 2
green 3
red 5
purple 6
I am trying to read in the entries of list.txt, then go to reads.txt and pull out the associated value.
the desired output would be:
green 3
purple 6
orange 0
if I write:
awk -F ' ' 'FNR == NR {keys[$1]; next} {if ($1 in keys) print $1,$2}' list.txt reads.txt
I get:
green 3
purple 6
but nothing for orange, and I need the line:
orange 0
If I write
awk -F ' ' 'FNR == NR {keys[$1]; next} {if ($1 in keys) print $1,$2; else print $1,0}' list.txt reads.txt
I get:
blue 0
green 3
red 0
purple 6
any ideas how to fix this?
major newbie here, so any help appreciated!