this seems to have an easy solution, but I am stuck. I would like to look up the second column of a main file in a key file, and for any matched key, print only the first 2 columns, but the entire record for the rest. I have a working script but that prints the entire line for the matched keys. Can you please help?
awk 'FNR == NR {key[$1]; next} $2 in key {print $1,$2}' keyfile mainfile > outfile
mainfile:
PSHELL 10 136514 0.7
PSHELL 15 136514 0.7
PSHELL 20 136513 2.0
PSHELL 30 13571 1.7
keyfile:
10
30
outfile:
PSHELL 10
PSHELL 15 136514 0.7
PSHELL 20 136513 2.0
PSHELL 30