variable context

variable context

am 20.11.2007 02:15:49 von swimmingly

I'm searching through logs in which transactions have a variable
number of lines above and below the search_string, so if I try using
gnu grep's -A and -B options, I either get too much or too little.
There are delimiter lines consisting of tildes in a row. How could I
select from a file all lines between tildes once the search_sting is
found.

For instance, in this file:

~~~~~~~~~~~~~
line a1
line a2
first transaction
line an
~~~~~~~~~~~~~
line b1
line b2
line b3
second transaction
search_string
line b6
line bn
~~~~~~~~~~~~~
line c1
.... etc
line cn
~~~~~~~~~~~~

it should just select context around the search_string in the second
one:

~~~~~~~~~~~~~
line b1
line b2
line b3
second transaction
search_string
line b6
line bn
~~~~~~~~~~~~~

Re: variable context

am 20.11.2007 06:49:47 von Janis Papanagnou

swimmingly wrote:
> I'm searching through logs in which transactions have a variable
> number of lines above and below the search_string, so if I try using
> gnu grep's -A and -B options, I either get too much or too little.
> There are delimiter lines consisting of tildes in a row. How could I
> select from a file all lines between tildes once the search_sting is
> found.
>
> For instance, in this file:
>
> ~~~~~~~~~~~~~
> line a1
> line a2
> first transaction
> line an
> ~~~~~~~~~~~~~
> line b1
> line b2
> line b3
> second transaction
> search_string
> line b6
> line bn
> ~~~~~~~~~~~~~
> line c1
> ... etc
> line cn
> ~~~~~~~~~~~~

(Is there a '~' character missing in the last line?)

>
> it should just select context around the search_string in the second
> one:
>
> ~~~~~~~~~~~~~
> line b1
> line b2
> line b3
> second transaction
> search_string
> line b6
> line bn
> ~~~~~~~~~~~~~
>

This is close...

awk 'BEGIN{ORS=RS="~~~~~~~~~~~~~"}/search_string/'


Janis