Here's a sed command, works great, just on every other line (simplified for your convenience):
cat testfile.txt | sed -E "/PATTERN/,/^>/{//!d;}"
if my testfile.txt is
>PATTERN 1 2 3 >PATTERN a b c >PATTERN 1 2 3 >PATTERN a b c >asdf 1 2 3 >asdf a b c Expected output:
>PATTERN >PATTERN >PATTERN >PATTERN >asdf 1 2 3 >asdf a b c actual output:
>PATTERN >PATTERN a b c >PATTERN >PATTERN a b c >asdf 1 2 3 >asdf a b c -An aisde-
(The actual goal is to find a one of a group of patterns then delete the stuff that comes after it until the next occurence of a ">" symbol {also delete that line which I can do by piping to a grep -v})
I more or less got guidance by following what I found here. I've had this work for me. Here's an exact example (not that you have the file to look at it)
for line in $(cat bad_results.txt) do echo "removing $line" cat 16S.fasta | sed "/$line/,/^>/{//!d;}" | grep $line -v > temp_stor.fasta done