Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message> 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.
Post Follow-up to this messageDoug 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.