Collecting header from another file

I want to add header description from a file by matching the 2nd col of another file. .

The lookup file is at

ftp://ftp.ncbi.nlm.nih.gov/pub/COG/KOG/kog

The table file looks like

comp1001565_c0_seq1     At1g14590       48.48   66      34      0       200     3       171     236     2e-16   82.8
comp10017_c0_seq1       Hs20533698      34.52   84      55      1       15      266     58      139     1e-07   53.1

So the two rows have 2nd cols as At1g14590 and Hs20533698.

At1g14590 is not found in the lookup file but Hs20533698 is classified under
[u]KOG0811 SNARE protein PEP12/VAM3/Syntaxin 7/Syntaxin 17 in
the lookup file.

desired output

comp1001565_c0_seq1     At1g14590       48.48   66      34      0       200     3       171     236     2e-16   82.8
comp10017_c0_seq1       Hs20533698      34.52   84      55      1       15      266     58      139     1e-07   53.1      KOG0811 SNARE protein PEP12/VAM3/Syntaxin 7/Syntaxin 17 

Try :

$ awk 'FNR==NR{if(/^\[/){h=$0;next}A[$2]=h;next}($2 in A){$0 = $0 OFS A[$2]}1' lookupfile table
1 Like