How do I get sed to print a range of lines until it sees two consecutive blank lines?
This should stop when it encounters two consecutive blank lines regardless of the odd/even pairing of the blank lines with non-blank lines:
Don't print the two blank lines:
sed -n 'N;/^\n$/q;P;D'
Print one of them:
sed -n 'N;/^\n$/{P;q};P;D'
Print both of them:
sed -n 'N;/^\n$/{p;q};P;D'
Edit:
And here's how you'd make that work in your range:
sed -n '/^TODO/,${N;/^\n$/q;P;D}'
Edit 2:
Per dan's (the OP) comments and edited requirements, this seems to work to find the pattern in a range that ends in two blank lines, multiple times in a file:
sed -n '/^TODO/,/^$/{H;N;/^\n$/{b};p}'