The succinct one-line description of this pretty nifty tool:
csplit (1) - split a file into sections determined by context lines
There is a tool for everything, and the something I had to do today involved splitting a text file of GDB backtraces into files so I could diff them and attempt to see why threads were getting backed up trying to flush an APC PHP cache. It was generated using an already lovely command involving sudo
, lsof
, grep
, awk
, gdb
, and a bash for
loop. Exciting story, I know.
Anyway, the file looked something like this, although each backtrace was ~20 frames deep so I've cut it down a tad:
[Thread debugging using libthread_db enabled]
0x00002ba56bf7b4c4 in __lll_lock_wait () from /lib64/libpthread.so.0
#0 0x00002ba56bf7b4c4 in __lll_lock_wait () from /lib64/libpthread.so.0
...
#19 0x00002ba56a4a67fb in ap_mpm_run ()
#20 0x00002ba56a480e48 in main ()
[Thread debugging using libthread_db enabled]
0x00002ba56bf7b4c4 in __lll_lock_wait () from /lib64/libpthread.so.0
#0 0x00002ba56bf7b4c4 in __lll_lock_wait () from /lib64/libpthread.so.0
...
#19 0x00002ba56a4a67fb in ap_mpm_run ()
#20 0x00002ba56a480e48 in main ()
[Thread debugging using libthread_db enabled]
0x00002ba56bf7b4c4 in __lll_lock_wait () from /lib64/libpthread.so.0
#0 0x00002ba56bf7b4c4 in __lll_lock_wait () from /lib64/libpthread.so.0
...
And then the magic of csplit:
csplit notes.txt '/Thread debugging/' '{*}'
Which left me files numbered xx00
through xx13
, each with one full backtrace so I could easily compare them to each other with both diff -u
and vimdiff
.
Comments (0)