Hi.

I have a txt file containing mutiple fasta sequences, and I'd like to replace Nth character in each sequence.

If I want to replace 10th character of each sequence in the example below, which linux command can I use?

    > sample1
    TATCCGATGCGACGTGCAGCG
    > sample2    
    CTAGCGTAGTGTCGACTGCAT
    > sample3
    GACTGACGTGACGTAGTCGAC


Thank you!


Assuming one-line sequences in your FASTA-formatted input, replace `X` with your character of interest:

    $ awk '{ \
        if ($0 ~ /^>/) { \
          print $0; \
        } \
        else { \
          printf("%s%c%s\n", substr($0, 1, 9), "X", substr($0, 11, length($0) - 10)); \
        } \
      }' in.fa > out.fa

If you have multi-line sequences in your FASTA input, you need to render them into single-line sequences before using this one-liner. See the following Biostars question (and answer) for a solution: https://www.biostars.org/p/9262/