This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to add a specific character into the specific location of header in fasta file?

Hi all,

I have many fasta file with the header like 0001|X. y, 00021|M. s. There is a space between X. and y or M. and s causing a problem. I would like to add an underline character _ to the header instead of existing space. Could you please help me out to this end? Sorry if the issue is basic, I find no school better than here for learning.

Thanks in advance

sequence header

If a line starts with >, replace space with _.

The line starts with >, but sorry I didn't get your point

1 answer

sed '/^>/s/ /_/' in.fasta > out.fasta

EDIT:

You need

sed '/^>/s/ /_/g' in.fasta > out.fasta

Thanks a lot Goutham. However, I found that there is more than one space in the header file, the command replace just the first space with "_". Is it a way to replace all spaces in the header with "_"?

sed '/^>/s/ /_/g' in.fasta > out.fasta

Many thanks for your help.

Log in to answer this question.