Trying to do a "lookup" in a pipeline, where the input looks like this:
alice 5 bob 7 ...
I want to look up codes in the second column in a database and return the corresponding name, and keep on trucking with the original and looked-up data.
cat source.tab | \ tee foo.tmp | \ cut -f 2 | \ dbstream ... -s "select(select name from my_lookup where code=?)" | \ paste foo.tmp -
Result should be:
alice 5 foo bob 7 bar ...
Imagine for a minute that
cat source.tab is really a long pipeline that does other pre-processing. And that
dbstream .. could be some other command, say
wget | jq.
Important: I only want to start the lookup process once.
a) is this a terrible idea, and if so what should I be doing instead?
b) is there a better pattern than
tee tmp | cut | "lookup" | paste tmp - ?