I have the following contents in my file file.txt
Start
1
2
3
5
end
Start
a
b
c
d
end
How do i use only awk to get the section which is at the end from "start" to "end" as follows?
Start
a
b
c
d
end
Tried efforts:
awk '/Start/ {{ f = 1;n++ }} f && n == 2; /end/ {{ f = 0 }}' file.txt
With
tac+awksolution, could you please try following.Explanation:
tacwill print Input_file in reverse order(from bottom to up manner), then passing its output toawkcommand and inawkcode printing from first occurrence ofendto till first occurrence ofstart. Exiting fromawkcode when first occurrence ofstartis found, again this output is being send totacwhich will reverse the output and post it in original form of Input_file.2nd solution: Using GNU
awkone could try like but it assumes that there is NO discrepancy(means after each start there is end keyword present in OP's Input_file else it will give false positive results) in start and end keywords appearance.