Skip to main content
more elaborate explanation
Source Link
mik
  • 1.4k
  • 11
  • 15

If you have awk you can do:

awk '/foo/{print b$0;b="";x=1;next} x{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence ofWhen a foo inappears, it prints buffer (b variable) and current line, and clears the buffer.

Otherwise, but only if foo already appeared (x variable) it buffers current line.

If you have awk you can do:

awk '/foo/{print b$0;b="";x=1;next} x{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence of foo in b variable.

If you have awk you can do:

awk '/foo/{print b$0;b="";x=1;next} x{b=b$0"\n"}' bar.log | less

When a foo appears, it prints buffer (b variable) and current line, and clears the buffer.

Otherwise, but only if foo already appeared (x variable) it buffers current line.

I don't like the
Source Link
mik
  • 1.4k
  • 11
  • 15

If you have awk you can do:

awk '/foo/{print b$0;b="";x=1;next};x x{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence of foo in b variable.

If you have awk you can do:

awk '/foo/{print b$0;b="";x=1;next};x{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence of foo in b variable.

If you have awk you can do:

awk '/foo/{print b$0;b="";x=1;next} x{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence of foo in b variable.

deleted 4 characters in body
Source Link
mik
  • 1.4k
  • 11
  • 15

If you have awk you can do:

awk 'x{x=2} '/foo/{print b$0;b="";x=1b$0;b="";x=1;next} x>1;x{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence of foo in b variable.

If you have awk you can do:

awk 'x{x=2} /foo/{print b$0;b="";x=1} x>1{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence of foo in b variable.

If you have awk you can do:

awk '/foo/{print b$0;b="";x=1;next};x{b=b$0"\n"}' bar.log | less

It buffers all lines since last occurence of foo in b variable.

simplified according to comment
Source Link
mik
  • 1.4k
  • 11
  • 15
Loading
Source Link
mik
  • 1.4k
  • 11
  • 15
Loading