Skip to content

Instantly share code, notes, and snippets.

@rcsheets
Created October 1, 2014 07:03
Show Gist options
  • Save rcsheets/66cd8e79d4afdb209835 to your computer and use it in GitHub Desktop.
Save rcsheets/66cd8e79d4afdb209835 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use warnings;
use strict;
use v5.12;
# have:
# time [PID]: [sessionID-1] db=databaes,user=user,remote=remote TYPE: rest
# want:
# time|user|database|session ID|log entry type|rest
while (<>) {
chomp;
/^(?<time>\d{4}-\d{2}-\d{2}\s\d\d:\d\d:\d\d\.\d\d\d\sPDT)\s # timestamp
\[\d+\]:\s # PID
\[(?<sessionid>\d+)-1\]\s
db=(?<db>.*?),user=(?<user>.*?),remote=[^A-Z]+
(?<type>[A-Z]+):\s+(?<rest>.*)$/x;
printf "%s|%s|%s|%s|%s|%s\n",
$+{time}, $+{user}, $+{db}, $+{sessionid}, $+{type}, $+{rest};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment