the usual
inconsistent at best
Perl Log Processing Goodies

Here are some Perl goodies I forget to write down once I’ve remembered them long enough to solve my problem.

Line range

If you want to print all the lines in a file after a certain line number:

perl -ne 'print if (2655641 .. -1)' some.log

This will print from line 2655641 to the last line (-1).

Omiting chunks

Sometimes you have chunks of lines, or multi-line records, that you want to skip.

perl -ne 'print unless /inbound request/../^\}$/' some.log

This will skip chunks that begin with a line that includes ‘inbound request’ and that end with a line with a single curly brace:

[Mon Sep 22 03:25:16 2014] [info] [10.20.192.79] inbound request: {
  "ad-request-start" => "1411377916094000",
  "ad-request-stop" => "1411377916094000",
  "api-request-api-id" => "B11AFC88",
  "api-request-authtype" => "NAVU22RI",
  "api-request-method" => "GET",
  "api-request-start" => "1411377916049008",
  "api-request-stop" => "1411377916560696",
  "api-request-uri" => "/v1/accounts/B11AFC88",
  "api-server" => "api.example.com",
  "cs-request-duration" => "0.00000000000000",
  "ss-request-start" => "1411377915580000",
  "ss-request-stop" => "1411377915580000",
  "ui-request-start" => 0,
  "ui-request-stop" => "1411377831652000"
}

Last modified on 2014-09-24