Part 1
What is the easiest way to create a text filter which outputs only text surrounded by two predefined marks. I don't mind using any standard tool: sed, awk, python, ...
For example, i would like only the text surrounded by "Mark Begin" and "Mark End" to appear.
input:
Text 1
Mark Begin
Text 2
Mark End
Text 3
Mark Begin
Text 4
MarK End
Text 4
output:
Text 2
Text 4
Part 2
How can the solution be modified so that only the last occurrence will be written to output, so for the same input above, we get:
output:
Text 4
part 1
part 2
A functional (state-less) implementation using Python and lazy generators:
And now your second request is trivial (see iterlast here):
I found a good solution:
for second case, but it will require mark filtering after all.
To output each:
To output the last