Artificial intelligent assistant

How to add strings from a name list file to another file? I have a fasta file (seq.fa) which is a standard file format for genetic info, like so: >TR1|c0_g1_i1 GTCGAGCATGGTCTTGGTCATCTTCCTTTCAAAGAA >TR6|c0_g1_i1 GTGGAATATCGCCAGTGACCATCACTGATTAACCTG I also have a file with names matching the headers (">TR..." names): TR1|c0_g1_i1 scaf0432344_50037.734_wgs TR6|c0_g1_i1 scaf0159424_10142.072_wgs I need to make the "scaf0..." identifiers the first thing coming after the ">" file in the seq.fa. I want to keep the "TR..." identifiers which are unique to each of my sequences, like so: >scaf0432344_50037.734_wgs|TR1|c0_g1_i1 GTCGAGCATGGTCTTGGTCATCTTCCTTTCAAAGAA >scaf0159424_10142.072_wgs|TR6|c0_g1_i1 GTGGAATATCGCCAGTGACCATCACTGATTAACCTG The names file is in the same order as the sequences file! Haven't tried anything since I'm not trained and have no idea what I'm doing :/

With `awk`


awk 'FNR==NR{
a[">"$1]=$2;next
}
$1 in a{
sub(/>/,">"a[$1]"|",$1)
}1' file2 seq.fa


Get the scaf value from file2 and save it in an array `a` with index `">"$1`.

If `$1` of seq.fa is an index in array `a` substitute the `$1` to include the scaf value `a[$1]` after `>`.

Then print all lines in `seq.fa`

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 5d221c716492327d8497481cb05dd725