How to SED with open boundaries? [duplicate]

I was thinking too complicated the slicing in the How to express variables efficiently for SED? I want to include (a,b), not [a,b] like this don_crissti's command:

sed '/begin{document}/,/end{document}/!d;/end{document}/q' data.tex


So I do not want to include \begin{document} and \end{document} in the output. How can you having an open interval in the output?

There are many ways to do so. I suppose that is more undestandable (choice interval and remove which you don't like to include:

sed '/begin{document}/,/end{document}/!d;/begin{document}/d;/end{document}/d' data.tex


or with don-crissti's receipt:

sed '/begin{document}/,/end{document}/!d;//d' data.tex


Other way is start printing after begin in loop till the finish line:

sed -n '/begin{document}/{:;n;/end{document}/!{p;b;};}' data.tex

• @Masi Check modified. What kind of explanation you need more? Sep 11 '15 at 14:12
• How do you explain this {:;n;/end{document}/!{p;b;};}? It is rather cryptic to me. Sep 11 '15 at 14:15
• Yes, your commands work as expected in GNU SED. Good! Sep 11 '15 at 14:25
• @Masi : — mark; n — get next line ; /end{document}/! — line, which not (!) consist pattern; p — print ; b — return to mark Sep 11 '15 at 14:40
• Why do you need the return mark b? Sep 11 '15 at 14:52