Skip to content

Instantly share code, notes, and snippets.

@codingtiger
Created October 20, 2016 15:31
Show Gist options
  • Save codingtiger/3312fa4f15f3bac6abfc6edf1ca5d446 to your computer and use it in GitHub Desktop.
Save codingtiger/3312fa4f15f3bac6abfc6edf1ca5d446 to your computer and use it in GitHub Desktop.

Revisions

  1. codingtiger created this gist Oct 20, 2016.
    14 changes: 14 additions & 0 deletions split-nginx-log.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/sh

    awk 'BEGIN {
    split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ", months, " ")
    for (i = 1; i <= 12; i++)
    m[months[i]] = i
    }{
    split($4,array,/\[|:|\//)
    year = array[4]
    month = sprintf("%02d", m[array[3]])
    day = array[2]
    hour = array[5]
    print > "access."year"-"month"-"day"-"hour".log"
    }' access.log