I need to parse a file, and I'm looking to print a segment of data between two specific lines. From a "range start" to "range end" but only if the "range end" is present.
If the source file is:
[This is the start] of some data this is information this is more information This is does not contain the ending required [This is the start] of some other data this is info I want this is info I want [This is the ending I was looking for]
It should print:
[This is the start] of some other data this is info I want this is info I want [This is the ending I was looking for]
Using grep I've been able to find the data I need and print upwards, but only by a fix number of lines.
Given that the number of lines of data is not constant, is there a way I can use grep or sed, to work up from the end line to find the next occurrence of a given string and capture the specific range I want?
The "range start" of the data segment should be printed along with any data between the "range start" and "range end" point, and the "range end" match is what determines if the whole range of lines should be printed at all. If a range (data segment) does not have the specified end, it should not be printed. If multiple segments have an end point, then all segments containing an end should be printed. No case exists where the input file will have an end without a start, or multiple ends to a single start.
Print lines between (and including) two patterns does not solve my problem, as it starts printing on the first line matched and keeps printing until the the first end segment is found. I need to print only the segments that contain the specified end statement.