This sounds a bit more complex that what I've done with sed.
I think you could use the pattern range of of /PATTERN1/,/PATTERN2/ and have a subpattern match test for the lines in between. If the line matches PATTERN1, add the line to the multiline buffer. If that test fails and the line doesn't match PATTERN2, it is a line between the patterns, so add that also to the multiline buffer. If it matches PATTERN2, then test the multiline buffer for n return characters and delete it if it matches.
Code:
/PATTERN1/,/PATTERN2/{
/PATTERN1/N;
/PATTERN2/!N;
/PATTERN2/s/<multiline pattern>//d;n
}
and then use a subrange so that if the pattern on the line being read is PATTERN1 or neither pattern, add the line to the buffer. If the line being read is PATTERN2, then use a search/replace that matches [b]n[b] return characters.
I'm not certain from your question whether you want to delete an inclusive range or an exclusive range, that is to say, delete everything between the patterns or delete the patterns as well. Also, I'm not certain if by
n lines you mean exactly n lines or at least n lines.
I think a pattern like PATTERN1([^\n]*\n[^\n]*){[b]n[\n]}PATTERN2 if you use the extended regex option might do for the substitution test.
The two PATTERNs on the ends can serve as anchors so that a pattern with more than [b]n[b] return characters won't match.
----
I'll admit that I supplied a rough idea only, and it isn't tested at all. There are often cases pop up during testing that can throw a monkey wrench into the works. Such as if PATTERN1 or PATTERN2 might be split between lines. When using the 'n' or 'N' command, sometimes being on the last line in the file can goof things up.
-----
Here is a link to an online version of the first edition of "Sed & Awk".
http://doc.novsu.ac.ru/oreilly/unix/sedawk/index.htm
For learning awk, the gawk source package gives you access to the docbook source of "Gawk: Effective Awk Programming".
If it is an rpm, installing the patches "rpmbuild -bp gawk.spec", cd'ing to the BUILD/gawk-<version>/ directory and running:
./configure
make pdf
Will give you a pdf version of this book. It is excellent. I wish the sed package supplied one as good. The sed manual has strange examples such as emulating 'tac' or a calulator. Practical examples such as the one you presented would have been much better.
It's one thing to be thown in the deep end---cliff diving is not to way to learn how to swim.