I want to extract only the n first occurrences of
starttext(
some text
endtext)
in text file F.
I've tried experimenting with sed:
sed - '/starttext/,/endtext/p' inputfile
... this will give me ALL the ranges between starttext and endtext in inputfile. But I only want the first n ranges...
File F:
starttext(
sometext1
more text
endtext)
starttext(
sometext2
pineapple
endtext)
starttext(
sometext3
orange
banana
endtext)
starttext(
sometext4
some other text
endtext)
starttext(
sometext5
coconut
endtext)
starttext(
sometext6
endtext)
Fake command
sed - '/starttext/,/endtext/p' ((get the top 3 instances) inputfile
Epected output:
starttext(
sometext1
more text
endtext)
starttext(
sometext2
pineapple
endtext)
starttext(
sometext3
orange
banana
endtext)
I was asked to provide the following:
Also tell us if there can be nested ranges, or overlapping ranges, or starts with no end or ends with no start.
There is always an endtext after each starttext. Ranges are not nested or overlapping.
Also do you want to look for the start and end as regexps or strings?
Strings
And do you want to do a full-line match or partial line or something else?
I want the full line match from starttext to the full line of endtext with all the text (several lines) in between.