Skip to content

Instantly share code, notes, and snippets.

@hideshi
Created December 8, 2013 13:41
Show Gist options
  • Save hideshi/7857653 to your computer and use it in GitHub Desktop.
Save hideshi/7857653 to your computer and use it in GitHub Desktop.
Script for parsing LTSV formatted log.
$ cat ltsv.log
host:127.0.0.1 user:- time:[08/Feb/2013:14:17:53 +0900] req:GET / HTTP/1.1 status:200 size:6 referer:- ua:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17 taken:41
host:127.0.0.1 user:- time:[08/Feb/2013:14:17:53 +0900] req:GET /favicon.ico HTTP/1.1 status:404 size:6 referer:- ua:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17 taken:36
$ awk -F \t '{print "---";for(i=1;i<=NF;i++) {match($i,":");print substr($i,0,RSTART-1) "\t", substr($i,RSTART+1);}}' ltsv.log
$ awk -F \t '/status:404/ {print "---";for(i=1;i<=NF;i++) {match($i,":");print substr($i,0,RSTART-1) "\t", substr($i,RSTART+1);}}' ltsv.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment