[JM%|%Jorge Moreno%|%] 2006-02-10 - Here is a frontend for LogParser<
> (from M$, http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx) Very powerful text file parser, from what I reviewed and tried: * SQL like query definition * output to a file, console, chart, Database * multiple text files treated as a single set of data * handles various input file types (CSV, TSV, XML,etc) * much more... ---- screenshot: [logParserFE] ---- Step 1, Get the sample data: http://www.briandunning.com/sample-data/ file: us-500.zip (which contains us-500.csv) Make sure you convert the sample file to DOS format CR+LF (it is Unix format -LF-)<
> You can do that by opening in excel and then overwriting to CSV format, or change the format with your favorite text editor. ---- Step 2, Prepare your query in a separate file<
> filename: query.sql, contents:<
> SELECT first_name,last_name,city FROM us-500.csv WHERE state = 'CA' ---- Dependecies in this example: * the path to LogParser is hard-coded "C:\Program Files (x86)\Log Parser 2.2" * the default query file called "query.sql" mentioned above You will see some code being reused from this wiki (like [RS]'s proc '''e'get''') used in [e: a tiny editor plugin for eTcl] ---- [JM] 2006-Feb-13 cleaning up a little bit ---- [JM] 2006-Nov-4 just added stderr output to a file if there is any error message coming from LogParser ---- [JM] 2015-Feb-9 coming back to this page after many years to refresh its contents ---- console show set types {*.sql} proc e'get name { if [file exists $name] { set f [open $name] set ::g(filename) $name K [read $f] [close $f] } else {corp $name} } proc K {a b} {set a} proc showSQL sqlFile { .ctrls.qryPath delete 0 end .ctrls.qryPath insert end $sqlFile .ctrls.sql delete 1.0 end foreach line [split [e'get $sqlFile] \n] { .ctrls.sql insert end $line\n } } frame .t frame .ctrls set log [text .t.log -width 80 -height 30 \ -borderwidth 2 -relief raised -setgrid true \ -yscrollcommand {.t.scroll set}] scrollbar .t.scroll -command {.t.log yview} canvas .c -height 20 -width 640 set but [button .ctrls.run -text "run" -command Run] button .ctrls.qry -text "Select Query..." -command {set query [tk_getOpenFile -filetypes [list [list "All files" $types]]] showSQL $query } entry .ctrls.qryPath -width 50 button .quit -text "exit" -command exit text .ctrls.sql -width 40 -height 10 pack .quit pack .t.scroll -side right -fill y pack .t.log -side left -fill both -expand true pack .t -side top -fill both -expand true pack .c grid .ctrls.qry .ctrls.qryPath grid .ctrls.run .ctrls.sql pack .ctrls #default header file set header "[pwd]/header.txt" #default query file set query "[pwd]/query.sql" if [file exists $query] { .ctrls.qryPath insert end $query showSQL $query } else { tk_messageBox -message "There is no default query file defined\n ($query was expected)" } proc Run {} { global input log but command header query $log insert end "-\n" puts [pwd] if {[catch {open "|\"C:/Program Files (x86)/Log Parser 2.2/LogParser.exe\" \ -i:CSV file:$query\ -headerRow:ON\ 2> errfile.txt" r+} input]} { $log insert end "$input\n" } else { fconfigure $input -blocking 0 -buffering none -translation auto fileevent $input readable Log $but config -text Stop -command Stop } } proc Log {} { global input log if [eof $input] { Stop } else { gets $input line $log insert end ">>> $line\n" $log see end } } proc Stop {} { global input log but set line "done....\if there is LogParser errors, see: errfile.txt" $log insert end $line\n $log see end catch {close $input} $but config -text "run" -command Run } ---- 7/4/2009, [JM] see also [LogParser goes COM] ---- <> <> Application | File | Parsing