timeslot.awk
Generated on Tue Dec 05 17:39:05 Eastern Standard Time 2006 from timeslot.awk
# Program : TIMESLOT.AWK
# Purpose : Parse through log file and count entries per hour
# Date : 16 November 2001
# Author : Bob Jonkman <bjonkman@sobac.com>
# Copyright 2008 Bob Jonkman and/or SOBAC Microcomputer Services
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Modified : 19 March 2001 : Changed input file date format to "yyyy/mm/dd hh:mm:ss"
# Input Format : POAname/MTAname, Datetime, Message
# Input Datetime format is "yyyy-mm-dd hh:mm:ss"
# Output Format: Datetime, Slot count
# Output DateTime format is "yyyy-mm-dd hh:00:00"
BEGIN { print "Date Time, No. of Entries";
FS=","; # input field separator
OFS=","; # output field separator
SUBSEP=" " # substring separator
}
# Don't read the header info in FNR==1
FNR!=1 {
# separate Date (datetime[1]) from Time (datetime[2])
split($2,datetime," ") ;
# separate Time into Hour (time[1]), Minute (time[2]) and Second (time[3])
split(datetime[2],time,":") ;
# increment slot for (date, hour)
total++ ;
if(!slot[datetime[1], time[1]])
{
unique++;
}
slot[datetime[1], time[1]]++ ;
if (prevtotal + 10000 <= total)
{
print("Total: " total " Unique: " unique) > "/dev/stderr"
prevtotal = total ;
}
# print $0 ; # === DEBUG ===
# print ( "field2=" $2 ", datetime1=" datetime[1] ",datetime2=" datetime[2] ", time1=" time[1] ", time2=" time[2] ", slot=" slot[datetime[1] " " time[1]] ) # ===DEBUG===
}
END {
for (i in slot)
{
# print "##### DEBUG ##### i=" i, "datetime1=" datetime[1], "datetime2=" datetime[2], "slot=" slot[i]
print i ":00:00", slot[i] | "sort"
}
print("=====") ;
print(total, "Total") ;
print(unique, "Unique") ;
}
# EOF: TIMESLOT.AWK
1 files processed.