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.
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.
Using sed to only replace literal question mark characters on non-header lines:
sed -i.bak '/^>/!s/?/N/g' /path/to/fasta/*.fasta
If your FASTA files are gzipped, just use a for loop:
for f in ./fasta/*.fasta.gz ; do
cp "${f}" "${f}.bak" &&
zcat "${f}.bak" | sed '/^>/!s/?/N/g' | gzip > "${f}"
done