[JM%|%Jorge Moreno%|%] 2006-02-10 - Here is a frontend for LogParser<
> (from M$, http://www.microsoft.com/technet/scriptcenter/tools/logparser/default.mspx) * Of course, windows only * Very incomplete, proof of concept only 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 (Its original format is Unix format so LF only for line termination)<
> 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 ---- [JM] 2017-Jan-27 coming back -again- to this page after so many years to refresh its contents ---- console show set types {*.sql} proc invoke command { global fh set fh [open |$command r+] set stdout [read $fh] set stderr {} set status [catch {close $fh} stderr e] if {$status} { dict with e {} lassign [set -errorcode] sysmsg pid exit if {$sysmsg eq {NONE}} { #output to stderr caused [close] to fail. Do nothing } elseif {$sysmsg eq {CHILDSTATUS}} { return [list $stdout $stderr $exit] } else { return -options $e $stderr } } return [list $stdout $stderr 0] } 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 fh log but command header query puts [pwd] set results [invoke "\"C:/Program Files (x86)/Log Parser 2.2/LogParser.exe\" -i:CSV file:$query -headerRow:ON"] $log insert end "[lindex $results 0]" $log insert end "[lindex $results 1]" $log see end } ---- See also: * [LogParser goes COM] * [Sqawk] ---- <> <> Application | File | Parsing