How can extract the lines between two patterns which are not unique ?
Example:-
data of type samplex
name a
property b
data of type samplex
name c
property d
data of type samplex
name e
property f
data of type sampley
name g
property h
I want to search between the pattern "data of type samplex" and get all occurrences of the lines between them.
First occurrence:-
name a
property b
Second occurrence:-
name c
property d
Third occurrence:-
name e
property f
For getting the first occurrence alone and when the two patterns are different,
sed '/pattern1/,/pattern2/p;/pattern2/q' <file> will work.
How can I tweak this command for my requirement?
sampley
in the last one is a typo, or if you want everything fromdata of type samplex
todata of type anything
.Nth occurrence:-
added? Do you want to remove the lines aftersampley
?