{"id":3066,"date":"2010-06-02T11:15:00","date_gmt":"2010-06-02T11:15:00","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/using-logparser-part-2\/"},"modified":"2016-09-02T11:37:41","modified_gmt":"2016-09-02T11:37:41","slug":"using-logparser-part-2","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/using-logparser-part-2\/","title":{"rendered":"Using LogParser &#8211; part 2"},"content":{"rendered":"<p><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/blogbits\/jonathan.allen\/UsingLogParserpart1_12E3F\/Person_Address.zip\">PersonAddress.csv<\/a> <br \/> <a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/blogbits\/jonathan.allen\/UsingLogParserpart1_12E3F\/Sales_SalesOrderDetail.zip\">SalesOrderDetail.tsv<\/a> <br \/> In <a href=\"https:\/\/www.simple-talk.com\/blogs\/using-logparser-part-1\/\">part 1 of this series<\/a> we downloaded and installed <a href=\"http:\/\/www.microsoft.com\/downloads\/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&amp;displaylang=en\">LogParser<\/a> and used it to list data from a csv file. That was a good start and in this article we are going to see the different ways we can stream data and choose whether a whole file is selected. We are also going to take a brief look at what file types we can interrogate.<\/p>\n<p>If we take the query from part 1 and add a value for the output parameter as -o:datagrid so that the query becomes <strong>LOGPARSER &#8220;SELECT top 15 * FROM C:LPperson_address.csv&#8221; -o:datagrid <\/strong>and run that we get a different result. A pop-up dialog that lets us view the results in a resizable grid.<\/p>\n<p><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/blogbits\/jonathan.allen\/UsingLogParserpart2_12EE5\/fxofn5le.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/blogbits\/jonathan.allen\/UsingLogParserpart2_12EE5\/fxofn5le_thumb.jpg\" alt=\"fxofn5le_thumb.jpg\" width=\"584\" height=\"205\" \/><\/a><\/p>\n<p>Notice that because we didn&#8217;t specify the columns we wanted returned by LogParser (we used <strong>SELECT *<\/strong>) is has added two columns to the recordset &#8211; <em>filename <\/em>and <em>rownumber<\/em>. This behaviour can be very useful as we will see in future parts of this series. You can click <u>N<\/u>ext 10 rows or <u>A<\/u>ll rows or close the datagrid once you are finished reviewing the data.<\/p>\n<p>You may have noticed that the files that I am working with are different file types &#8211; one is a csv (comma separated values) and the other is a tsv (tab separated values). If you want to convert a file from one to another then LogParser makes it incredibly simple. Rather than using &#8216;datagrid&#8217; as the value for the output parameter, use &#8216;csv&#8217;:<\/p>\n<p><strong>logparser &#8220;SELECT SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, OrderQty, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount, LineTotal, rowguid, ModifiedDate into C:Sales_SalesOrderDetail.csv FROM C:Sales_SalesOrderDetail.tsv&#8221; -i:tsv -o:csv<\/strong><\/p>\n<p>Those familiar with SQL will not have to make a very big leap of faith to making adjustments to the above query to filter in\/out records from the source file. Lets get all the records from the same file where the Order Quantity (OrderQty) is more than 25:<\/p>\n<p><strong>logparser &#8220;SELECT SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, OrderQty, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount, LineTotal, rowguid, ModifiedDate into C:LPSales_SalesOrderDetailOver25.csv FROM C:LPSales_SalesOrderDetail.tsv WHERE orderqty &gt; 25&#8221; -i:tsv -o:csv<\/strong><\/p>\n<p>Or we could find all those records where the Order Quantity is equal to 25 and output it to an xml file:<\/p>\n<p><strong>logparser &#8220;SELECT SalesOrderID, SalesOrderDetailID, CarrierTrackingNumber, OrderQty, ProductID, SpecialOfferID, UnitPrice, UnitPriceDiscount, LineTotal, rowguid, ModifiedDate into C:LPSales_SalesOrderDetailEq25.xml FROM C:LPSales_SalesOrderDetail.tsv WHERE orderqty = 25&#8221; -i:tsv -o:xml<\/strong><\/p>\n<p>All the standard comparison operators are to be found in LogParser; &gt;, &lt;, =, LIKE, BETWEEN, OR, NOT, AND.<\/p>\n<h3>Input and Output file formats.<\/h3>\n<p>LogParser has a pretty impressive list of file formats that it can parse and a good selection of output formats that will let you generate output in a format that is useable for whatever process or application you may be using.<\/p>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\">\n<p><strong>From any of these<\/strong><\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<td valign=\"top\"><strong>To any of these<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>IISW3C<\/a>: parses IIS log files in the W3C Extended Log File Format.<\/p>\n<\/td>\n<td rowspan=\"20\" valign=\"middle\"> \u00a0<\/td>\n<td valign=\"top\">\n<p><a>NAT<\/a>: formats output records as readable tabulated columns.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>IIS<\/a>: parses IIS log files in the Microsoft IIS Log File Format.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>CSV<\/a>: formats output records as comma-separated values text.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>BIN<\/a>: parses IIS log files in the Centralized Binary Log File Format.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>TSV<\/a>: formats output records as tab-separated or space-separated values text.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>IISODBC<\/a>: returns database records from the tables logged to by IIS when configured to log in the ODBC Log Format.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>XML<\/a>: formats output records as XML documents.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>HTTPERR<\/a>: parses HTTP error log files generated by Http.sys.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>W3C<\/a>: formats output records in the W3C Extended Log File Format.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>URLSCAN<\/a>: parses log files generated by the URLScan IIS filter.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>TPL<\/a>: formats output records following user-defined templates.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>CSV<\/a>: parses comma-separated values text files.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>IIS<\/a>: formats output records in the Microsoft IIS Log File Format.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>TSV<\/a>: parses tab-separated and space-separated values text files.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>SQL<\/a>: uploads output records to a table in a SQL database.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>XML<\/a>: parses XML text files.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>SYSLOG<\/a>: sends output records to a Syslog server.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>W3C<\/a>: parses text files in the W3C Extended Log File Format.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>DATAGRID<\/a>: displays output records in a graphical user interface.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>NCSA<\/a>: parses web server log files in the NCSA Common, Combined, and Extended Log File Formats.<\/p>\n<\/td>\n<td valign=\"top\">\n<p><a>CHART<\/a>: creates image files containing charts.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>TEXTLINE<\/a>: returns lines from generic text files.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>TEXTWORD<\/a>: returns words from generic text files.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>EVT<\/a>: returns events from the Windows Event Log and from Event Log backup files (.evt files).  <\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>FS<\/a>: returns information on files and directories.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>REG<\/a>: returns information on registry values.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>ADS<\/a>: returns information on Active Directory objects.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>NETMON<\/a>: parses network capture files created by NetMon.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>ETW<\/a>: parses Enterprise Tracing for Windows trace log files and live sessions.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\n<p><a>COM<\/a>: provides an interface to Custom Input Format COM Plugins.<\/p>\n<\/td>\n<td valign=\"top\">\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>So, you can query data from any of the types on the left and really easily get it into a format where it is ready for analysis by other tools. To a DBA or network Administrator with an enquiring mind this is a treasure trove.<\/p>\n<p>In part 3 we will look at working with multiple sources and specifically outputting to SQL format. See you there!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PersonAddress.csv SalesOrderDetail.tsv In part 1 of this series we downloaded and installed LogParser and used it to list data from a csv file. That was a good start and in this article we are going to see the different ways we can stream data and choose whether a whole file is selected. We are also&#8230;&hellip;<\/p>\n","protected":false},"author":101210,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[7630],"class_list":["post-3066","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/101210"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=3066"}],"version-history":[{"count":5,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3066\/revisions"}],"predecessor-version":[{"id":67550,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3066\/revisions\/67550"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=3066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=3066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=3066"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=3066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}