O'Reilly logo

Text Processing with Ruby by Rob Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example: Parsing Log Files

Generally the one-liners that you might find yourself writing fall into two categories: problems that are too simple or too temporary to ever commit to a file, or problems that are exploratory in nature, where you might eventually write a script but aren’t ready to do so just yet.

Let’s look at an example of the latter, a case of exploring a file to gather information about its contents. The file we’ll be looking at is a log file for the popular web server software Apache. Its error logs look something like this:

 
[Tue Dec 30 15:25:20 2014] [error] Directory index forbidden
 
[Tue Dec 30 15:26:11 2014] [notice] caught SIGTERM, shutting down
 
[Tue Dec 30 15:26:14 2014] [notice] Digest: generating secret ...
 
[Tue Dec ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required