Home > Archive > AWK > November 2004 > getting a block of data help
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]
| Author |
getting a block of data help
|
|
| Doug VT 2004-11-22, 3:56 am |
| Hello all,
I am pretty good at lsh and sed, but awk eludes me atm, so am looking
for some help. I have a file with the following format:
(bunch of lines I don't care about)
*
* xxxxxxx SUMMARY:
*
(a few more lines that vary)
****************************************
*******
Not sure which would be easier, but basically I want to search for the
SUMMARY statement and then print that line up to the
******************** line
OR if that is not easily done then, print the SUMMARY line and the
next 12 lines following it.
Any help would be appreciated.
Thanks,
Doug
| |
| Joe Farish 2004-11-22, 3:56 am |
| > OR if that is not easily done then, print the SUMMARY line and the
> next 12 lines following it.
I know someone has already posted the prefered solution but here is my
attempt at the alternative solution:
awk '/SUMMARY:/{a = 1}{if (a == 1) {b = b + 1}}{if ((b >= 1) && (b <
14)) {print}}' INPUT
How it works:
When AWK finds SUMMARY: a is assigned the value of 1.
When a = 1, the value of b is increased by one everytime a new line is
read.
As long as B is between 0 and 14 the line will be printed.
| |
| Janis Papanagnou 2004-11-22, 3:56 am |
| Doug VT wrote:
> Hello all,
>
> I am pretty good at lsh and sed, but awk eludes me atm, so am looking
> for some help. I have a file with the following format:
>
> (bunch of lines I don't care about)
> *
> * xxxxxxx SUMMARY:
> *
> (a few more lines that vary)
> ****************************************
*******
>
> Not sure which would be easier, but basically I want to search for the
> SUMMARY statement and then print that line up to the
> ******************** line
awk '/SUMMARY:/,/^\*\*+$/'
i.e. up to a line containing only stars and at least two of it (if
you don't want to count and escape each star).
> OR if that is not easily done then, print the SUMMARY line and the
> next 12 lines following it.
>
> Any help would be appreciated.
>
> Thanks,
>
> Doug
Janis
|
|
|
|
|