Using sed on the mysql slow query log
October 18, 2010
Sed is one of those great UNIX utilities which is well impenetrable enough that I have to lookup examples every time I want to do something with it.
But, for dipping into huge log files it’s great. Here’s a simple command for grabbing all the lines in a log file after the appearance of some text. In this case I’m looking for all lines from my Mysql slow query log after a given date:
cat db1-slow.log | sed -n '/Time: 081026/,$ s/.*/&/p' > slow-oct26.log
The -n option to sed turns off line echo, then the /p command enables printing matching lines. The regexp supplied before the s/../p part makes that command take effect after that pattern is matched.
Advertisement
No comments yet