如何使用正则表达式搜索属于某一时间段的日志
我想在大量的日志文件里搜索属于某个时间段日志行出来,每行日志都有时间的,时间格式为YYYY/MM/DD hh:mm:ss,给定的时间段是不定的,可能会跨分钟、跨小时、跨天、跨月,甚至可能跨年。例如要搜索2012/12/25 到2013/01/04这几天里每天12:00 ~ 14:00的日志。如何把这些日志grep出来?
awk 'BEGIN{print mktime("2012 12 25 10 23 10")}'
mktime(datespec) Turns datespec into a time stamp of the same form as returned by systime(). The datespec is a string of the form YYYY MM DD HH MM SS[ DST]. The contents of the string are six or seven numbers represent- ing respectively the full year including century, the month from 1 to 12, the day of the month from 1 to 31, the hour of the day from 0 to 23, the minute from 0 to 59, and the second from 0 to 60, and an optional daylight saving flag. The values of these numbers need not be within the ranges specified; for example, an hour of -1 means 1 hour before midnight. The origin-zero Gregorian calendar is assumed, with year 0 preceding year 1 and year -1 preceding year 0. The time is assumed to be in the local timezone. If the daylight saving flag is positive, the time is assumed to be daylight saving time; if zero, the time is assumed to be standard time; and if negative (the default), mktime() attempts to determine whether daylight saving time is in effect for the specified time. If datespec does not contain enough elements or if the resulting time is out of range, mktime() returns -1.
awk字符串比较打印就可以吧?
awk '$1>"date1"&&$1<"date2"{print}'
|