Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
A comma-separated-values (CSV) log consists of two primary components:
In both header and record lines, commas separate individual fields. By contrast, in a tab-separated-values (TSV) log, tab characters separate fields.
For example, in DHCPSrvLog.log, the header line and the first two record lines look something like the following:
ID Date,Time,Description,IP Address,Host Name,MAC Address 10,04/02/01,15:16:00,Assign,192.168.1.10,workstation1.fabrikam.com,0000F8083446, 10,04/02/01,15:16:00,Assign,192.168.1.11,workstation2.fabrikam.com,0000F8083447,
To parse a CSV log, the script needs to read in each line and then extract each field within the line. This can be done using the VBScript Split function, which splits a line into constituent parts based on the field delimiter (the character used to separate the individual fields). For example, this line:
Part 1,Part 2,Part 3,Part 4
Would be split into a four-item array, with the array consisting of the following elements:
Listing 12.17 contains a script that parses a CSV file. To carry out this task, the script must perform the following steps:
The first 25 lines in a DHCP server log are always header information that is not required for this script. You must start at the beginning of the file and explicitly skip these lines, however, because the FileSystemObject always begins reading at the first line of the file. You cannot specify an alternative starting point, such as the 26th line of the file.
Each variable (representing a comma-delimited field in the log) is stored in the array arrDHCPRecord.
In a production script, you would probably either save selected variables to a database or take some action based on the value of one or more of those variables (for example, the Event ID).
Listing 12.17 Parsing a Comma-Separated-Values Log
|
|
Send us your feedback | « Previous | Next » |