|
Home > Archive > Unix Shell > November 2007 > variable context
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| swimmingly 2007-11-19, 7:26 pm |
| 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
~~~~~~~~~~~~~
| |
| Janis Papanagnou 2007-11-20, 1:37 am |
| 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
|
|
|
|
|