Awk 将文件1中的ID替换为文件2的ID

Awk 将文件1中的ID替换为文件2的ID,awk,sed,fasta,Awk,Sed,Fasta,我有两个文本文件,我想用file2的id替换file1的id。两个文件中的所有ID顺序相同 File1 >12_abc ghfghfjgfhjgfjf hgfjfgjgfjfgjgfjf >13_def ghfghgfgfgfghfjhf nmbnmbhjgkjgjhggh >14_ghi uytghhuytuytuytuyt ytrftyfrghfhgfgfgg File2 >12_abc|10 >13_def|20 >14_ghi|30 Desired

我有两个文本文件,我想用file2的id替换file1的id。两个文件中的所有ID顺序相同

File1
>12_abc
ghfghfjgfhjgfjf
hgfjfgjgfjfgjgfjf
>13_def
ghfghgfgfgfghfjhf
nmbnmbhjgkjgjhggh
>14_ghi
uytghhuytuytuytuyt
ytrftyfrghfhgfgfgg

File2
>12_abc|10
>13_def|20
>14_ghi|30

Desired Output
>12_abc|10
ghfghfjgfhjgfjf
hgfjfgjgfjfgjgfjf
>13_def|20
ghfghgfgfgfghfjhf
nmbnmbhjgkjgjhggh
>14_ghi|30
uytghhuytuytuytuyt
ytrftyfrghfhgfgfgg

awk'{print}!(NR%2){if((getline<“File2.txt”)>-1)print}File1

这看起来像一个FASTA文件,非常尴尬。我会这样做:

如果要按顺序替换名称:

awk '(NR==FNR){a[FNR]=$0;next}/^>/{print a[++c]; next}1' File2 File1 > File1.new
awk -F '|' '(NR==FNR){a[$1]=$0;next}/^>/{print a[$0]; next}1' File2 File1 > File1.new
如果要根据内容替换名称:

awk '(NR==FNR){a[FNR]=$0;next}/^>/{print a[++c]; next}1' File2 File1 > File1.new
awk -F '|' '(NR==FNR){a[$1]=$0;next}/^>/{print a[$0]; next}1' File2 File1 > File1.new