How to awk pattern over two consecutive lines? -


i trying guess done easy cant seem find answer. want use awk pick out lines between 2 patterns, want pattern match 2 consecutive lines. have tried find solution on internet bu perhaps did not search right keywords. example better describe this.

suppose have following file called test:

aaaa bbbb     content 1  ddddd     fffff   aaaa     cccc      content 2  ccccc     fffff 

for example lets find "some content 1"

then use awk this:

  cat test | awk  '/aaa*/ { show=1} show; /fff*/ {show=0}' 

but not want want. want somehow enter pattern:

  aaaa*\nbbbb* 

and same end pattern. suggestions how this?

you can use this:

awk  '/aaa*/ {f=1} /bbb*/ && f {show=1} show; /fff*/ {show=f=0}' file bbbb     content 1  ddddd fffff 

if pattern1 aaa* set flag f
if pattern2 bbb* , flag f true, set show flag


if need print patter1 aaa*?

awk  '/aaa*/ {f=$0} /bbb*/ && f {show=1;$0=f rs $0} show; /fff*/ {show=f=0}' file aaaa bbbb     content 1  ddddd fffff 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -