Extract sequences from partial Header
You could use Biopython. If its a fasta file, it will be complicated to write fasta output (especially multiline fasta) with grep or awk. Simple solution is to use biopython, so that you can even match for any complex patterns in the fasta header.
from Bio import SeqIO

rna_records  = []
dna_records = []

for seq in SeqIO.parse(&quot;in.fa&quot;,&quot;fasta&quot;):

    if &quot;RNA&quot; in seq.id:
        rna_records.append(seq)

    elif &quot;DNA&quot; in seq.id:
        dna_records.append(seq)

SeqIO.write(rna_records, &quot;RNA_out.fa&quot;,&quot;fasta&quot;)
SeqIO.write(dna_records, &quot;DNA_out.fa&quot;,&quot;fasta&quot;)

This code needs to be optimised if you are dealing with large sequences like human genome fasta as it holds everything in memory.