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.
AWK split nginx log
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment