linux - Awk between two patterns with pattern in the middle -


hi looking awk can find 2 patterns , print data between them file if in middle there third patterns in middle. example:

start 1 2 middle 3 end start 1 2 end  , output be: start 1 2 middle 3 end 

i found in web awk '/patterns1/, /patterns2/' path > text.txt need output third patterns in middle.

and here solution without flags:

$ awk 'begin{rs="end"}/middle/{printf "%s", $0; print rt}'  file start 1 2 middle 3 end 

explanation: rs variable record separator, set "end", each record separated "end".

then filter records contain "middle", /middle/ filter, , matched records print current record $0 , separator print rt


Comments

Popular posts from this blog

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -