Skip to content

Instantly share code, notes, and snippets.

@adamatan
Created January 23, 2013 12:14
Show Gist options
  • Select an option

  • Save adamatan/4604933 to your computer and use it in GitHub Desktop.

Select an option

Save adamatan/4604933 to your computer and use it in GitHub Desktop.
AWK: Extract text between two delimiters. Write each match to file/
# First thread dump line
/^Full thread dump Java/ {
thread_dump=1;
counter++;
lines=0;
filename="Thread_dump_"counter".txt";
printf "Found thread dump #%-4d\t", counter
}
# Last thread dump text block
/^Heap[:space:]*$/ {
thread_dump=2;
}
# Last thread dump line - first blank line after "Heap"
{ if (thread_dump==2 && $0 ~ "^[:space:]*$") {
thread_dump=0;
printf "(%5d lines)\n", lines;
}
}
# Print line only if in thread dump block
{ if (thread_dump!=0) {
print $0 > filename;
lines++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment