How to extract lines between same patterns from a file

awkregular expressionsed

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?

Best Answer

sed 's:data of type samplex:\n:g' File_name -i

This code will replace the said string with newline so that you will get required info. Use -i option to save the changes in original file only.

Related Question