On 2/24/2008 3:50 PM, DanielC wrote:
[Please don't top-post, fixed below.]
> Thanks, Ed, but the built-in "mktime" only works with the format "2008
02 24
> 09 14 03".
>
> What I'm tring to do is to count the lines which time is within the past
5
> minutes in the below logfile:
>
> [2008-02-24 21:07:08.149124] 6451642 196612 547 0 6839170
> [2008-02-24 21:07:08.202526] 9330060 196612 555 0 15649568
> [2008-02-24 21:07:08.358302] 7052812 196612 561 0 11683309
> [2008-02-24 21:07:08.403536] 8814437 196612 555 0 10075256
> [2008-02-24 21:07:08.916245] 8315044 196612 550 0 7098662
> [2008-02-24 21:07:09.247885] 5694065 196612 549 0 10033038
> [2008-02-24 21:07:09.276933] 9282129 196612 549 0 12066863
> [2008-02-24 21:07:09.462647] 9794128 196612 449 0 16793249
> [2008-02-24 21:07:09.476629] 6601802 196612 556 0 15964258
> [2008-02-24 21:07:09.665840] 9088251 196612 558 0 17974450
>
>
> # awk -F "[].[]+" '{print $2}' /tmp/logfile
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
>
> However, # awk -F "[].[]+" 'system("date +%s -d " $2)' /tmp/logfile
doesn't.
>
> "Ed Morton" <morton@[EMAIL PROTECTED]
> wrote in message
> news:47C1E058.1080508@[EMAIL PROTECTED]
>
>>
>>On 2/24/2008 3:06 PM, DanielC wrote:
>>
>>>I tried to use awk to convert time format, but got below errors:
>>>
>>># awk 'BEGIN {system("date +%s -d " "09:14:03")}'
>>>1203844443
>>># awk 'BEGIN {system("date +%s -d " "2008-02-24 09:14:03")}'
>>>date: too many non-option arguments: 09:14:03
>>>Try `date --help' for more information.
>>>
>>
>>$ awk 'BEGIN {system("date +%s -d " "2008-02-24 09:14:03")}'
>>date: extra operand `09:14:03'
>>Try `date --help' for more information.
>>$ awk 'BEGIN {system("date +%s -d " "\"2008-02-24 09:14:03\"")}'
>>1203866043
>>
>>Of course, with GNU awk you could just use it's built in time
functions...
>>
>>Ed.
>>
> Thanks, Ed, but the built-in "mktime" only works with the format "2008
02 24
> 09 14 03".
then just change your input to that format
> What I'm tring to do is to count the lines which time is within the past
5
> minutes in the below logfile:
>
> [2008-02-24 21:07:08.149124] 6451642 196612 547 0 6839170
Look:
$ echo "[2008-02-24 21:07:08.149124] 6451642 196612 547 0 6839170" |
awk '{print gensub(/\[(....)-(..)-(..) (..):(..):(..).*/,"\\1 \\2 \\3 \\4
\\5
\\6","")}'
2008 02 24 21 07 08
> [2008-02-24 21:07:08.202526] 9330060 196612 555 0 15649568
> [2008-02-24 21:07:08.358302] 7052812 196612 561 0 11683309
> [2008-02-24 21:07:08.403536] 8814437 196612 555 0 10075256
> [2008-02-24 21:07:08.916245] 8315044 196612 550 0 7098662
> [2008-02-24 21:07:09.247885] 5694065 196612 549 0 10033038
> [2008-02-24 21:07:09.276933] 9282129 196612 549 0 12066863
> [2008-02-24 21:07:09.462647] 9794128 196612 449 0 16793249
> [2008-02-24 21:07:09.476629] 6601802 196612 556 0 15964258
> [2008-02-24 21:07:09.665840] 9088251 196612 558 0 17974450
>
>
> # awk -F "[].[]+" '{print $2}' /tmp/logfile
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:08
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
> 2008-02-24 21:07:09
>
> However, # awk -F "[].[]+" 'system("date +%s -d " $2)' /tmp/logfile
doesn't.
>
Doesn't what? What do you want the output to be?
Ed.


|