Try this, if you have GNU grep
(the default on Linux systems):
grep -E --no-group-separator -i -B 1 '^[ACGTNacgtn]+$''^[ACGTN]\+$' input.fasta > filtered.fasta
Explanation: find all lines that are composed of only A/C/G/T/N (case insensitive search), and show that line plus the preceding line. Don't put any breaks between matches that are not consecutive.
This should work on both multi-line and single line fasta files.