Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the last matching block 1

Status
Not open for further replies.

mrsleepy

Technical User
Jun 12, 2006
4
US
I am trying to snip out Java Thread dumps from potentially very large files - the one I am testing on is 60MB. The section of interest will always begin with a line like:

Full thread dump Java HotSpot(TM) Client VM (1.4.2_07-b05 mixed mode):

And end just before a line like this - a Warning or Error - I don't mind an extra line at the end but wouldn't mind losing it.

**** Warning Sat Apr 01 03:15:21 EST 2006 1143879321293 / ServletUtil atg.service.resourcepool.ResourcePoolException: attempt to obtain a resource from a pool that is not running atg.service.resourcepool.ResourcePoolException: attempt to obtain a resource from a pool that is not running

awk '/Full thread dump/,"****"==$1' jvmoutput.log > ThreadDump.log

Gets me that - but if there are multiple dumps within the log file I only want the last one.
 
Typed, untested:
awk '/Full thread dump/{i=1}i{a[i++]=$0}"****"==$1{i=0}END{for(j=1;j<i;++j)print a[j]}' jvmoutput.log > ThreadDump.log

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Typed (and tested):
awk '/Full thread dump/{i=1}i{a[i++]=$0}"****"==$1{[!]k=i;[/!]i=0}END{for(j=1;j<[!]k[/!];++j)print a[j]}' jvmoutput.log > ThreadDump.log

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Works like a cham. Thanks, you're a lifesaver.
 
OK, one little problem. It doesn't work when there is only one dump present in the file.
 
Is that because there is no '**** Warning' after the dump? If so, set k=i at the beginning of the END clause perhaps?

Annihilannic.
 
awk '/Full thread dump/{i=k=1}i{a[k++]=$0}"****"==$1{i=0;--k}END{for(j=1;j<k;++j)print a[j]}' jvmoutput.log > ThreadDump.log

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top