#!/usr/bin/tclsh # # convert logfile to TAB separated list, for easy inputting to MySQL ###################################################################### # This is how you port your old logfile, to the new format: # # first run "mymalog" to generate the "database" and "logbook". # # cd to your logfile dir and do and run this program: # # to_my tab_sep_logfile # # and start mysql: # mysql # mysql> use database; # mysql> load data local infile 'tab_sep_logfile' into table logbook; # # your old logfile is now in the MySQL database ready to use. # ##################################################################### # set logfile stdin set outfile stdout # read the first line, which is the logstructure set logstructure [gets $logfile] # then read the rest of the input set i 1 foreach line [split [read $logfile] \n] { if {( $i > 0 ) && ($line != {}) } { puts -nonewline $outfile "$i\t TF3MA\t" foreach dalk $logstructure { set value "[lindex $line [lsearch -exact $logstructure $dalk]]" if { ($dalk == "TIME_ON") || (($dalk == "TIME_OFF" ) && ($value != ""))} { append value "00" } puts -nonewline $outfile "$value\t" } puts $outfile "" } incr i }