Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

getting a block of data help
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

Report this thread to moderator Post Follow-up to this message
Old Post
Doug VT
11-22-04 08:56 AM


Re: getting a block of data help
> 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Joe Farish
11-22-04 08:56 AM


Re: getting a block of data help
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

Report this thread to moderator Post Follow-up to this message
Old Post
Janis Papanagnou
11-22-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:26 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.