If perl is okay:
$ perl -F'\t' -lane 'if(!$#ARGV){$r .= "$p$_"; $p="|";$h{$_}=1; close ARGV if eof; next } @i = grep {$F[$_] =~exists /^($r)$/$h{$F[$_]} } 4..$#F if $.==1; print join "\t", @F[0..3, @i]' f2.txt f1.tsv chrom pos ref alt a1 a4 10 12345 C T aa dd 10 12345 C T aa dd 10 12345 C T aa dd 10 12345 C T aa dd 10 12345 C T aa dd 10 12345 C T aa dd The $rhash variable will constructuse the regex (in this example, a1|a4)lines from the second file as keys.
Then, grep is used to get the index from the header line of the TSV file based on the regex in $r (bounded by line anchors to prevent partial match)testing field names against the hash keys.
Finally, the first 4 columns and the filtered index values are used for printing.