This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Is there a way to change only the header of a fasta file?

Dear All,

I would like to change the header of the fasta file as follows, but I don't know how. The actual file is so long that I need a command. Could you tell me the command to change only the header.

Before

>TRINITY_DN22056_c0_g1_i1 len=300 path=[0:0-299] GTCCATTTGACTGATTCCCATTCCAAAAAAAACCACTCAACCAGGACTGACGCATAAAACCGTCAAATCGACGACGCAGGATAAGGTTCGATTATGACTTGTTACGGTCTCAAAGGCGCGTTTTTACACAATTATG >TRINITY_DN30979_c0_g1_i1 len=300 path=[0:0-299] TGACGAATGAGAACAAGGGCACGCAGTTCGTTTTATGTCAATTGAACTGCTGGTCACTAACCAGAATTCGTATTCCCGTTGGACGTCAATTTGCATAAAAAATGTAAAAGAGAAAATACGATCATAAAAAGTGGAAA

After

>AbTRINITY_DN22056_c0_g1_i1 len=300 path=[0:0-299] GTCCATTTGACTGATTCCCATTCCAAAAAAAACCACTCAACCAGGACTGACGCATAAAACCGTCAAATCGTACGACGCAGGATAAGGTTCGATTATGACTTGTTACGGTCTCAAAGGCGCGTTTTTACACAATTATG >AbTRINITY_DN30979_c0_g1_i1 len=300 path=[0:0-299] TGACGAATGAGAACAAGGGCACGCAGTTCGTTTTATGTCAATTGAACTGCTGGTCACTAACCAGAATTCGTATTCCCGTTGGACGTCAATTTGCATAAAAAATGTAAAAGAGAAAATACGATCATAAAAAGTGGAAA

This question may not exactly be a bioinformatics question. If this was inappropriate, I apologize. Thank you for your help.

awk seqkit fasta

A simple Linux command can do it:

sed 's/>/>Ab/' your.fasta > your.new.fasta

or modify in place:

sed -i 's/>/>Ab/' your.fasta

Good point, thanks.

2 answers

sed 's/^>/>Ab/'

So simple! I've learned a lot. Thank you very much!

$ bioawk -c fastx '{print ">Ab"$name;print $seq}' test.fa

Log in to answer this question.