-
Notifications
You must be signed in to change notification settings - Fork 1
/
cacti-split-yrmt.awk
44 lines (42 loc) · 1.2 KB
/
cacti-split-yrmt.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Split Cacti log by year and month
# Written by Georgi D. Sotirov <[email protected]>
#
# Different versions of cacti wrote timestamps as
# DD/MM/YYYY HH:MM:SS [AM|PM]
# or as
# YYYY-MM-DD HH:MM:SS
# or as
# YYYY/MM/DD HH:MM:SS
# so all three need to be matched. In all cases date is in the 1st field
# separated by space.
# In frist case year is 3rd and months is 2nd field separated by slash.
# In second and third cases year is 1st and months is 2nd field separated by
# dash or slash.
#
/^[0-9]{2}\/[0-9]{2}\/[0-9]{4} [0-9]{2}:[0-9]{2}:[0-9]{2} (AM|PM)?/ {
split($1, dat, "/");
if ( FILENAME == "-" )
LOG_FNAME = "cacti.log"
else
LOG_FNAME = FILENAME
fn = sprintf("%s-%d%02d", LOG_FNAME, dat[3], dat[2])
print > fn
}
/^[0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/ {
split($1, dat, "-");
if ( FILENAME == "-" )
LOG_FNAME = "cacti.log"
else
LOG_FNAME = FILENAME
fn = sprintf("%s-%d%02d", LOG_FNAME, dat[1], dat[2])
print > fn
}
/^[0-9]{4}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/ {
split($1, dat, "/");
if ( FILENAME == "-" )
LOG_FNAME = "cacti.log"
else
LOG_FNAME = FILENAME
fn = sprintf("%s-%d%02d", LOG_FNAME, dat[1], dat[2])
print > fn
}