Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: Bash script...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 7 Topic 2105 of 2341
Post > Topic >>

Re: Bash script timing out

by Ed Morton <morton@[EMAIL PROTECTED] > Jan 3, 2008 at 06:27 PM

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.
 




 7 Posts in Topic:
Bash script timing out
cozzmo1@[EMAIL PROTECTED]  2007-12-19 10:47:04 
Re: Bash script timing out
Kees Nuyt <k.nuyt@[EMA  2007-12-19 21:19:12 
Re: Bash script timing out
Ed Morton <morton@[EMA  2007-12-19 17:44:46 
Re: Bash script timing out
cozzmo1@[EMAIL PROTECTED]  2007-12-21 08:54:47 
Re: Bash script timing out
Ed Morton <morton@[EMA  2007-12-21 12:34:46 
Re: Bash script timing out
cozzmo1@[EMAIL PROTECTED]  2008-01-03 08:23:56 
Re: Bash script timing out
Ed Morton <morton@[EMA  2008-01-03 18:27:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 27 18:01:16 CDT 2008.