Replacing a character in multiple fasta files within a folder
2
0
Entering edit mode
13 months ago

How can I replace a character in multiple fasta files within a folder? More specific, I want to replace the character "?" by "N" through multiple fasta files.

replace find and • 509 views
2
Entering edit mode
13 months ago
Mensur Dlakic ★ 20k

Assuming that your files all end in .fasta, go to that directory and type:

find . -name "*.fasta" | xargs -i sed -i 's/\?/N/g' {}


Yet another approach:

for f in *.fasta ; do sed -i 's/\?/N/g' \$f ; done

0
Entering edit mode

Hi Mensur Dlakic,

Thanks so much! It worked. I also found another way: sed -i -se 's/?/N/g' *.fasta.

0
Entering edit mode
13 months ago

look at find /path/to/dir -exec and Remove unwanted characters from FASTA file

0
Entering edit mode

Thanks for your prompt response, however I do not want to remove the character "?", I want to replace it by "N". I tried sed -i 's/?/N/g' *, but with no success.

The fact that all of my files end with the letter "A" before the format denomination seems to be an issue for the command.

Do you have an idea how to solve this?