On 1/3/2008 10:23 AM, cozzmo1@[EMAIL PROTECTED]
wrote:
<snip>
> $ more ttt
> echo "start"
delete the above echo and add the below BEGIN section
> /usr/xpg4/bin/awk '
BEGIN{ print "start" }
> !/^\*\*\*.*Auto.Closed.*/ && !/^\*\*\*.*Closed/ && !/^$/ {
> if (/^[1-6][0-9][0-9][0-9][0-9].*[a-z,A-Z]*$/) {
> split($0,f,",")
> ticket = f[1]
> print ticket,f[6],f[7],"Opened"
> } else if (/^\*\*\*.*Not.Approved*/) {
> split($0,f," ")
> print ticket,f[6],f[7],"Not-Approved"
> } else if (/^\*\*\*.*Picked.Up.*/||/\*\*\*.*Complete.*/||/\*\*
> \*.*Approved.*/) {
> split($0,f," ")
> print ticket,f[4],f[5],f[7]
> }
> }
>
> ' "$1"
>
> -------
>
> gives the output of
>
> host $ ttt yak1 | more
> start
> 32645 2007-09-26 16:14:00 Opened
> 32645 09-26-2007 16:38 Picked
> 32645 09-26-2007 16:38 Approved
> 32645 09-27-2007 07:11 Complete
> 32646 2007-09-26 16:42:00 Opened
> 32646 09-26-2007 17:30 Picked
> 32646 09-26-2007 17:38 Approved
> 32646 09-27-2007 16:57 Complete
> 32647 2007-09-26 17:21:00 Opened
> 32647 09-26-2007 17:27 Picked
> 32647 09-27-2007 13:53 Approved
> 32647 09-27-2007 14:27 Complete
> etc <snip>
>
> Since we are dealing with Military time here I don't think a simple
> algorithm will do, it would be cool to find how long the tickets are
> opened, since the date may change, and the "Opened" fields have a
> different date/time format, that adds a lot of complexity.
It's actually pretty easy with GNU awk's time functions.
> Presently I paste the output into Excel and it does a fair job of
> computing the time, but I would like to be able to have the script do
> it.
>
> desired example.
> 32645 2007-09-26 16:14:00 Opened 0:00
> 32645 09-26-2007 16:38 Picked 0:24
> 32645 09-26-2007 16:38 Approved 0:24
> 32645 09-27-2007 07:11 Complete 14:33
>
> Thanks,
> Cozzmo
>
> -------
Try this untested script (NOTE: it's GNU awk, not /usr/xpg4/bin/awk):
gawk '
BEGIN{ print "start" }
!/^\*\*\*.*Auto.Closed.*/ && !/^\*\*\*.*Closed/ && !/^$/ {
if (/^[1-6][0-9][0-9][0-9][0-9].*[a-z,A-Z]*$/) {
split($0,f,",")
ticket = f[1]
# time = f[6] f[7] = 2007-09-26 16:14:00
split(f[6]" "f[7],t,"[- :]")
startSecs = mktime(t[1]" "t[2]" "t[3]" "t[4]" "t[5]" "t[6])
print ticket,f[6],f[7],"Opened",0
} else if (/^\*\*\*.*Not.Approved*/) {
split($0,f," ")
print ticket,f[6],f[7],"Not-Approved"
} else if (/^\*\*\*.*Picked.Up.*/||/\*\*\*.*Complete.*/||/\*\*
\*.*Approved.*/) {
split($0,f," ")
# time = f[4] f[5] = 09-26-2007 16:38
split(f[4]" "f[5],t,"[- :]")
curSecs = mktime(t[3]" "t[1]" "t[2]" "t[4]" "t[5]" 0")
print ticket,f[4],f[5],f[7],curSecs - startSecs
}
}
' "$1"
That should print the number of seconds since the ticket was "Opened".
Reformating that into min:secs and doing the same for "Not-Approved", if
applicable, left as an exercise...
Ed.


|