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

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -