Deleting Lines Containing Text in vi

One of the more tedious aspects of development is debugging. Apache logs often provide a lot of useful information about things that have gone wrong, some related to code, some not (honestly, script kiddies, quit trying to access phpmyadmin).

The problem is, if a mistake is encountered a lot, you wind up with a log filled with the same error, over and over ... and over again. I like to work with the log files and delete the lines as I solve the related problem. A handy (and powerful) shortcut in vi makes this easy to do.

Let's say I discovered that I forgot to update the live database with a key redirect. The log file is littered with entries like:

[Fri Sep 06 08:33:31 2013] [error] [client 72.86.42.86] PHP Fatal error:  Uncaught exception
'IWException' with message 'Bad page request: member/forks' in ...

I simply eliminate all the lines containing member/forks.

:g/member\/forks/d

And now, I can continue my analysis without constant reminders of the now-fixed error.