Skip to content

Using sed on the mysql slow query log

October 18, 2010
by

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.