Code:
sed '/^type2/,/^$/d'
Code:
awk '/^type2/,/^$/{next}1'
Things get a bit more complicated with grep. There are
lots of grep-like tools, some of them better suited to the task on hand than others. Broadly speaking, I'd divide tools I deem "well-suited" in this context into three categories. Sadly, GNU grep (or any traditional grep implementation) is in no one of these.
First, tools that can operate on paragraphs rather than on lines of text:
greple (written in Perl) and
paragrep (written in Python). Their only disadvantage is that they are lesser known and rarely provided by Linux distributions, so you may have to install them from CPAN and PyPI, respectively.
Code:
greple -p -v type2 .
Then, there's
sgrep which is a category in and by itself. It's an old tool, last updated in 2004, but still surprisingly useful at times. Beware though that despite its name,
sgrep doesn't understand regular expressions. So, "type2" in the example below is a literal string.
Code:
sgrep -Nao '' '"type2".."\n\n"'
Lastly, there are tools that 1) allow matching across the lines, AND 2) allow
-v/
--invert-match to be used while doing so. For example,
pcregrep that comes with
the PCRE library, or
ripgrep:
Code:
pcre2grep -Mvx 'type2(?s).*?^'
Code:
rg -Uv '^type2(.+\n)+\n'