For Programmers: Free Programming Magazines  


Home > Archive > AWK > November 2005 > Re: generation of sequences









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: generation of sequences
Sebastian Luque

2005-11-07, 9:55 pm

"William James" <w_a_x_man@yahoo.com> wrote:

[...]

> /^Stage [0-9]/ {



> oldstage = stage
> oldincrement = increment
> oldstart = start


> stage = $2 + 0
> increment = substr($0,index($0,"*")+1) + 0
> start = get_start_time( $0 )


> # If there was a previous stage, and it wasn't
> # a stage 2, we need to generate its lines now.
> if ( oldstage && oldstage != 2 )
> { for (t=oldstart; t<start; t += oldincrement)
> print format_time(t) ",,,,"
> }



> next
> }


> 2 == stage {
> print format_time( start) "," $0
> start += increment
> }



> # Input: 26/04/05 start 08:30:00
> # Output: 2005 04 26 08 30 30
> function fix_date_string( s, a )
> { split( s, a, /[ :\/]/ )
> return sprintf( "%s %s %s %s %s %s",
> 2000+a[3], a[2], a[1], a[5], a[6], a[7] )
> }


> function get_start_time( s )
> {
> match( s, /Date / )
> return mktime( fix_date_string( substr(s, RSTART+RLENGTH) ))
> }


> function format_time( timestamp )
> { return strftime( "%d/%m/%Y, %H:%M:%S", timestamp )
> }


That works great and very instructive! Thank you.


--
Sebastian P. Luque
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com