ed(1), the standard text editor, has the reputation of being a bit terse. However, today I found it actually too chatty.
I was trying (for a test) to print all the label of the "completed" messages in a text format serialisation of a sequence of protobuffers. The pedantic way to do this, would be to take all lines starting with "completed" and for each, first go up the next line starting with "id", then down to the next line containing "label", and print that. Of course, for that test, a simple g/^completed/?label?p was more than sufficient, but what would be the correct way of doing it?
The problem is that / and ? addresses cannot be chained, i.e., ?^id?/label/ is not a valid address. So we have to use the fact that g accepts a command list.
g/^completed/?^id?p\ /label/p
For GNU ed, I found a solution, as there is a comment command(!).
(.,.)# Begins a comment; the rest of the line, up to a newline, is ignored. If a line address followed by a semicolon is given, then the current address is set to that address. Otherwise, the current address is unchanged.
g/^completed/?^id?;#\ /label/p
PS: I had to find that out that various ed also differ in where they output the answer of the e command (implicit at startup).