PDA

View Full Version : TCL script that parses file and converts date to timestamp


djdeluxe76
05-04-2005, 09:44 AM
Hello and thank you for reading this request post.

I was going to do/learn it myself but I just wind up dead .... its just
too much for the beginning.

Though I can feel for a pro this should not be much work especially
because I just need a basic script I can do the bug tracking myself
and learn something at the same time.

Basically it's just

1. open file,
2. parse (regexp) for YYYY-MM-DD HH:NN (2005-05-04 12:15)
3. and convert to unix epoch timestamp like (1114708730)

Anyone, please, with too much freetime at hands?

Much apreciated !!

Cheers
DJ

p.s.: I searched the forum with terms 'script convert timestamp' and
'convert timestamp' so i'm sorry if i've overlooked a post.

jeza
05-04-2005, 12:44 PM
set time_now [clock seconds]
set time_formated [clock format $time_now -format {%Y-%m-%d %H:%M:%S} -gmt true]
set file_time ""
set file_formated ""

if { [file exist "x:/path/file"] } {

set reply [open "x:/path/file" "r+"]

while {![eof $reply]} {

set line [gets $reply]

if { [regexp -nocase -- {[0-9]{1,4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}} $line out] } {

set file_time $out
set file_formated [clock scan "$out" -gmt true]

iputs -nobuffer "time_now......: $time_now"
iputs -nobuffer "time_formated.: $time_formated"
iputs -nobuffer "line..........: $line"
iputs -nobuffer "file_time.....: $file_time"
iputs -nobuffer "file_formated.: $file_formated"


}

}

close $reply

}

djdeluxe76
05-04-2005, 03:08 PM
hello Jeza

Thanks for replying so quickly giving me a beatiful insight here :)

I just found something called the Active TCL Manual so I guess its time
now to learn some stuff (read functions) you have used here..

When I finally get home I'm all eager to experiment with your code.

Thank you!
DJ

djdeluxe76
05-04-2005, 04:52 PM
one question though if you dont mind.... i can't seem to find "iputs" only "puts" ... what is the difference in this case please?

cheers
DJ

neoxed
05-04-2005, 05:04 PM
The "iputs" command is provided by ioFTPD, to write to the control channel.

For a list of other ioFTPD specific Tcl commands, check the following posts:

http://www.ioftpd.com/board/showthread.php?s=&threadid=230
http://www.ioftpd.com/board/showthread.php?s=&threadid=1775

djdeluxe76
05-04-2005, 06:12 PM
ahh i understand. Thanks for pointing me in the right direction :)

thanks to you both guys!

Cheers
DJ