This is a test version of Biostars. For the public version, visit https://www.biostars.org.
fasta header with leading zeros

Hi, I would like to rename the sequences in my file to have leading zeros in front of the header name using unix or perl based on the number of sequences in the file. I am unable to open these files using a text editor since they are too large. Example.

>gmp-15 
>gmp-126
>gmp-127890 to
>gmp-000015
>gmp-000126
>gmp-127890

Thanks

sequence fasta

1 answer


awk -F "-" '{if(/^>/)printf("%s-%06d\n",$1,$2); else print $0}' file.fasta > out.fasta

That worked just great! Thanks so much! I really appreciate your help!

so validate 5heikiki's answer by clicking on the hand on the left please.

Please accept @5heikki's answer by clicking on the green check mark on the left of the answer.

Log in to answer this question.