Skip to main content
added 22 characters in body
Source Link
gringer
  • 15.1k
  • 5
  • 24
  • 83

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.

Try this, if you have GNU grep (the default on Linux systems):

grep -E --no-group-separator -B 1 '^[ACGTNacgtn]+$' input.fasta > filtered.fasta

Explanation: find all lines that are composed of only A/C/G/T/N, 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.

Try this, if you have GNU grep (the default on Linux systems):

grep --no-group-separator -i -B 1 '^[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.

You need -E (or -P) for the + modifier and the --no-group-separator and the -B are GNU options (comment edited Nov 5, 2022 at 13:11)
Source Link
terdon
  • 10.6k
  • 5
  • 23
  • 48

Try this, if you have GNU grep (the default on Linux systems):

grep -E --no-group-separator -B 1 '^[ACGTNacgtn]+$' input.fasta > filtered.fasta

Explanation: find all lines that are composed of only A/C/G/T/N, 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.

Try this:

grep --no-group-separator -B 1 '^[ACGTNacgtn]+$' input.fasta > filtered.fasta

Explanation: find all lines that are composed of only A/C/G/T/N, 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.

Try this, if you have GNU grep (the default on Linux systems):

grep -E --no-group-separator -B 1 '^[ACGTNacgtn]+$' input.fasta > filtered.fasta

Explanation: find all lines that are composed of only A/C/G/T/N, 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.

Source Link
gringer
  • 15.1k
  • 5
  • 24
  • 83

Try this:

grep --no-group-separator -B 1 '^[ACGTNacgtn]+$' input.fasta > filtered.fasta

Explanation: find all lines that are composed of only A/C/G/T/N, 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.