Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Chart text file data

Reply
 
Old 06-07-2008   #1 (permalink)
Flowering Weeds


 
 

Chart text file data


When any one of the many computers or
machines (running almost any Windows
language) out there needs to parse data
(local or remote) then perhaps try the free
Windows data parser tool, IIS's Microsoft's
data parser, Log Parser 2.2 (with built-in
Microsoft ChartSpace chart maker) and
perhaps chart the output too!

Here using PowerShell:

# Create a data text file with
# no header row.

@"
Year One,10
Year Two,20
Year Three,30
"@ | out-file years.txt -encoding ascii

$message = "Was the data file created?" +
"`nPress the enter (or return) key to see"
" "
read-host $message

# The below uses two Log Parser input formats.
#
# Input format: FS (FileSystem properties)
# Returns properties of files and folders
# LogParser.exe -h -i:fs
#
# Input format: TEXTLINE (TextLine Format)
# Parses entire lines out of generic text files
# LogParser.exe -h -i:textline

# The below uses two Log Parser output formats.
#
# Output format: NAT (Native Format)
# Displays output records in the console window
# LogParser.exe -h -o:nat
#
# Output format: DATAGRID (DataGrid Output Format)
# Displays fields in a DataGrid dialog
# LogParser.exe -h -o:datagrid

# Was the file created? Use
# Log Parser's datagrid.
LogParser.exe "SELECT Path
FROM years.txt " `
-i:fs -qn | foreach {
LogParser.exe "SELECT text AS ['$_']
FROM '$_' " -i:textline `
-o:datagrid -statsff }

$message = "Ready to see the Log Parser chart?" +
"`nPress the enter (or return) key"
" "
read-host $message

# The below uses the Log Parser
# Input format: CSV (CSV Format)
# Parses text files containing comma-separated values
# LogParser.exe -h -i:csv

# The below uses the Log Parser
# Output format: CHART (Chart Output Format)
# Writes output to a chart image file
# LogParser.exe -h -o:chart

LogParser.exe "SELECT
Field1 AS Year,
Field2 AS [Amount Totals]
INTO testChart
FROM years.txt " `
-i:csv -statsff -headerRowff `
-o:chart -valuesn -viewn `
-chartType:ColumnClustered

# Now create a data text file
# with a header row.

@"
Year,Amount
Year One,10
Year Two,20
Year Three,30
"@ | out-file years.txt -encoding ascii

$message = "Was the data file created?" +
"`nPress the enter (or return) key to see"
" "
read-host $message

# The below uses the Log Parser
# Input format: CSV (CSV Format)
# Parses text files containing comma-separated values
# LogParser.exe -h -i:csv

# The below uses the Log Parser
# Output format: DATAGRID (DataGrid Output Format)
# Displays fields in a DataGrid dialog
# LogParser.exe -h -o:datagrid

# Was the file created? Use
# Log Parser's datagrid.
LogParser.exe "SELECT *
FROM years.txt " `
-i:csv -o:datagrid -statsff

$message = "Ready to see the Log Parser chart?" +
"`nPress the enter (or return) key"
" "
read-host $message

# The below uses the Log Parser
# Input format: CSV (CSV Format)
# Parses text files containing comma-separated values
# LogParser.exe -h -i:csv

# The below uses the Log Parser
# Output format: CHART (Chart Output Format)
# Writes output to a chart image file
# LogParser.exe -h -o:chart

LogParser.exe "SELECT
Year, Amount
INTO testChart
FROM years.txt " `
-i:csv -statsff -headerRown `
-o:chart -valuesn -viewn `
-chartType:ColumnClustered `
-chartTitle:"Year Totals"

" "
"Done!"
" "

Notice: IIS does not need to be running
or installed in order to use Log Parser
for either data parsing or chart making.

Search the Internet
(and this newsgroup)
for usage of:

Microsoft's Log Parser
command line usage,
or fully script enabled
either in COM or .NET
(from the IIS group)

and

Microsoft's ChartSpace charting
as used within Log Parser, Excel
or even stand alone scripting in
either of COM or .NET usage
(via the Office group)

Just one of many examples of
PowerShell using Log Parser.



My System SpecsSystem Spec
Old 06-07-2008   #2 (permalink)
Brandon [MVP]


 
 

Re: Chart text file data

Are you a PM for Log Parser?

"Flowering Weeds" <floweringnoweedsno@xxxxxx> wrote in message
news:%23w7QJ9NyIHA.6096@xxxxxx
Quote:

>
> When any one of the many computers or
> machines (running almost any Windows
> language) out there needs to parse data
> (local or remote) then perhaps try the free
> Windows data parser tool, IIS's Microsoft's
> data parser, Log Parser 2.2 (with built-in
> Microsoft ChartSpace chart maker) and
> perhaps chart the output too!
>
> Here using PowerShell:
>
> # Create a data text file with
> # no header row.
>
> @"
> Year One,10
> Year Two,20
> Year Three,30
> "@ | out-file years.txt -encoding ascii
>
> $message = "Was the data file created?" +
> "`nPress the enter (or return) key to see"
> " "
> read-host $message
>
> # The below uses two Log Parser input formats.
> #
> # Input format: FS (FileSystem properties)
> # Returns properties of files and folders
> # LogParser.exe -h -i:fs
> #
> # Input format: TEXTLINE (TextLine Format)
> # Parses entire lines out of generic text files
> # LogParser.exe -h -i:textline
>
> # The below uses two Log Parser output formats.
> #
> # Output format: NAT (Native Format)
> # Displays output records in the console window
> # LogParser.exe -h -o:nat
> #
> # Output format: DATAGRID (DataGrid Output Format)
> # Displays fields in a DataGrid dialog
> # LogParser.exe -h -o:datagrid
>
> # Was the file created? Use
> # Log Parser's datagrid.
> LogParser.exe "SELECT Path
> FROM years.txt " `
> -i:fs -qn | foreach {
> LogParser.exe "SELECT text AS ['$_']
> FROM '$_' " -i:textline `
> -o:datagrid -statsff }
>
> $message = "Ready to see the Log Parser chart?" +
> "`nPress the enter (or return) key"
> " "
> read-host $message
>
> # The below uses the Log Parser
> # Input format: CSV (CSV Format)
> # Parses text files containing comma-separated values
> # LogParser.exe -h -i:csv
>
> # The below uses the Log Parser
> # Output format: CHART (Chart Output Format)
> # Writes output to a chart image file
> # LogParser.exe -h -o:chart
>
> LogParser.exe "SELECT
> Field1 AS Year,
> Field2 AS [Amount Totals]
> INTO testChart
> FROM years.txt " `
> -i:csv -statsff -headerRowff `
> -o:chart -valuesn -viewn `
> -chartType:ColumnClustered
>
> # Now create a data text file
> # with a header row.
>
> @"
> Year,Amount
> Year One,10
> Year Two,20
> Year Three,30
> "@ | out-file years.txt -encoding ascii
>
> $message = "Was the data file created?" +
> "`nPress the enter (or return) key to see"
> " "
> read-host $message
>
> # The below uses the Log Parser
> # Input format: CSV (CSV Format)
> # Parses text files containing comma-separated values
> # LogParser.exe -h -i:csv
>
> # The below uses the Log Parser
> # Output format: DATAGRID (DataGrid Output Format)
> # Displays fields in a DataGrid dialog
> # LogParser.exe -h -o:datagrid
>
> # Was the file created? Use
> # Log Parser's datagrid.
> LogParser.exe "SELECT *
> FROM years.txt " `
> -i:csv -o:datagrid -statsff
>
> $message = "Ready to see the Log Parser chart?" +
> "`nPress the enter (or return) key"
> " "
> read-host $message
>
> # The below uses the Log Parser
> # Input format: CSV (CSV Format)
> # Parses text files containing comma-separated values
> # LogParser.exe -h -i:csv
>
> # The below uses the Log Parser
> # Output format: CHART (Chart Output Format)
> # Writes output to a chart image file
> # LogParser.exe -h -o:chart
>
> LogParser.exe "SELECT
> Year, Amount
> INTO testChart
> FROM years.txt " `
> -i:csv -statsff -headerRown `
> -o:chart -valuesn -viewn `
> -chartType:ColumnClustered `
> -chartTitle:"Year Totals"
>
> " "
> "Done!"
> " "
>
> Notice: IIS does not need to be running
> or installed in order to use Log Parser
> for either data parsing or chart making.
>
> Search the Internet
> (and this newsgroup)
> for usage of:
>
> Microsoft's Log Parser
> command line usage,
> or fully script enabled
> either in COM or .NET
> (from the IIS group)
>
> and
>
> Microsoft's ChartSpace charting
> as used within Log Parser, Excel
> or even stand alone scripting in
> either of COM or .NET usage
> (via the Office group)
>
> Just one of many examples of
> PowerShell using Log Parser.
>
>
My System SpecsSystem Spec
Old 06-09-2008   #3 (permalink)
Karl Prosser[MVP]


 
 

Re: Chart text file data

Thats pretty sweet. The only thing i don't like is having to save the
data to a file first.. but thats not a biggie.

I'd love to see a powershell function that can look at your objects in
the collection and dynamically generate the logparser query - that would
be killer.

-Karl

Flowering Weeds wrote:
Quote:

> When any one of the many computers or
> machines (running almost any Windows
> language) out there needs to parse data
> (local or remote) then perhaps try the free
> Windows data parser tool, IIS's Microsoft's
> data parser, Log Parser 2.2 (with built-in
> Microsoft ChartSpace chart maker) and
> perhaps chart the output too!
>
> Here using PowerShell:
>
> # Create a data text file with
> # no header row.
>
> @"
> Year One,10
> Year Two,20
> Year Three,30
> "@ | out-file years.txt -encoding ascii
>
> $message = "Was the data file created?" +
> "`nPress the enter (or return) key to see"
> " "
> read-host $message
>
> # The below uses two Log Parser input formats.
> #
> # Input format: FS (FileSystem properties)
> # Returns properties of files and folders
> # LogParser.exe -h -i:fs
> #
> # Input format: TEXTLINE (TextLine Format)
> # Parses entire lines out of generic text files
> # LogParser.exe -h -i:textline
>
> # The below uses two Log Parser output formats.
> #
> # Output format: NAT (Native Format)
> # Displays output records in the console window
> # LogParser.exe -h -o:nat
> #
> # Output format: DATAGRID (DataGrid Output Format)
> # Displays fields in a DataGrid dialog
> # LogParser.exe -h -o:datagrid
>
> # Was the file created? Use
> # Log Parser's datagrid.
> LogParser.exe "SELECT Path
> FROM years.txt " `
> -i:fs -qn | foreach {
> LogParser.exe "SELECT text AS ['$_']
> FROM '$_' " -i:textline `
> -o:datagrid -statsff }
>
> $message = "Ready to see the Log Parser chart?" +
> "`nPress the enter (or return) key"
> " "
> read-host $message
>
> # The below uses the Log Parser
> # Input format: CSV (CSV Format)
> # Parses text files containing comma-separated values
> # LogParser.exe -h -i:csv
>
> # The below uses the Log Parser
> # Output format: CHART (Chart Output Format)
> # Writes output to a chart image file
> # LogParser.exe -h -o:chart
>
> LogParser.exe "SELECT
> Field1 AS Year,
> Field2 AS [Amount Totals]
> INTO testChart
> FROM years.txt " `
> -i:csv -statsff -headerRowff `
> -o:chart -valuesn -viewn `
> -chartType:ColumnClustered
>
> # Now create a data text file
> # with a header row.
>
> @"
> Year,Amount
> Year One,10
> Year Two,20
> Year Three,30
> "@ | out-file years.txt -encoding ascii
>
> $message = "Was the data file created?" +
> "`nPress the enter (or return) key to see"
> " "
> read-host $message
>
> # The below uses the Log Parser
> # Input format: CSV (CSV Format)
> # Parses text files containing comma-separated values
> # LogParser.exe -h -i:csv
>
> # The below uses the Log Parser
> # Output format: DATAGRID (DataGrid Output Format)
> # Displays fields in a DataGrid dialog
> # LogParser.exe -h -o:datagrid
>
> # Was the file created? Use
> # Log Parser's datagrid.
> LogParser.exe "SELECT *
> FROM years.txt " `
> -i:csv -o:datagrid -statsff
>
> $message = "Ready to see the Log Parser chart?" +
> "`nPress the enter (or return) key"
> " "
> read-host $message
>
> # The below uses the Log Parser
> # Input format: CSV (CSV Format)
> # Parses text files containing comma-separated values
> # LogParser.exe -h -i:csv
>
> # The below uses the Log Parser
> # Output format: CHART (Chart Output Format)
> # Writes output to a chart image file
> # LogParser.exe -h -o:chart
>
> LogParser.exe "SELECT
> Year, Amount
> INTO testChart
> FROM years.txt " `
> -i:csv -statsff -headerRown `
> -o:chart -valuesn -viewn `
> -chartType:ColumnClustered `
> -chartTitle:"Year Totals"
>
> " "
> "Done!"
> " "
>
> Notice: IIS does not need to be running
> or installed in order to use Log Parser
> for either data parsing or chart making.
>
> Search the Internet
> (and this newsgroup)
> for usage of:
>
> Microsoft's Log Parser
> command line usage,
> or fully script enabled
> either in COM or .NET
> (from the IIS group)
>
> and
>
> Microsoft's ChartSpace charting
> as used within Log Parser, Excel
> or even stand alone scripting in
> either of COM or .NET usage
> (via the Office group)
>
> Just one of many examples of
> PowerShell using Log Parser.
>
>
t
My System SpecsSystem Spec
Old 06-10-2008   #4 (permalink)
Ozone


 
 

Re: Chart text file data

I have seen several examples of PowerShell and LogParser, and most of
them look much like the example above. I use LogParser a lot with
PowerShell, but I use the COM approach instead. As you can see in the
example below, the $query and other variables are dynamic. This code
is actually an excerpt from a larger function that i use in a schedule
task to import IIS logs into a database. The LogParser CHM has the
COM Reference section...

#Sample LogParser and PowerShell COM Usage
#Logparser Com Objects
$logparser = New-Object -ComObject MSUtil.LogQuery
$inputformat = New-Object -ComObject MSUtil.LogQuery.W3CInputFormat
$outputformat = New-Object -ComObject MSUtil.LogQuery.SQLOutputFormat

$outputformat.server = $server
$outputformat.database = $database
$outputformat.driver = "SQL Server"

$query = "Select * INTO $tablename from $sourcefolder\$logfile"
$retrun = $logparser.ExecuteBatch($Query, $inputformat, $outputformat)

if ($return -eq $FALSE) {write-host "No Errors"}
if ($return -eq $TRUE) {write-host $logparser.errormessage}

HTH
Ozone
My System SpecsSystem Spec
Old 06-10-2008   #5 (permalink)
Flowering Weeds


 
 

Re: Chart text file data

Quote:

> You don't have to save the data
> to a file before you can process
> it with log parser:
Correct just use
FROM STDIN
instead of
FROM file.txt
Quote:

> I use LogParser a lot with
> PowerShell,
It is good to see some other
Windows data parser posts!
Quote:

> but I use the COM approach
> instead. As you can see in the
> example below, the $query
> and other variables are dynamic.
Yep and this "approach" can also be
done using the .NET Log Parser wrappers
(which is nice since the Windows automation
tool, PowerShell, is a .NET process)!

Also another "dynamic" way,
and perhaps the most common way,
is plain old text files usage!

These text files (any name and extension)
are Log Parser query files (with parms usage)
that are then called by Log Parser.

Check one's data (collection)
Create (or use) a query file
Call Log Parser

LogParser.exe file:myFile.lpQuery?a="$stuff"
-i:textline -o:tpl -tpl:mytemplate.tpl

Just one of many examples of the
automation tool, PowerShell automating
the Windows data parsing tool, Log
Parser.


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Convert hostname text file to IP text file VB Script
Data Parsing Chart Output Engine PowerShell
Howto: Add lines of text from a specific point in a text file.. VB Script
How do I read a text file and sort text by fixed positions? PowerShell
[demo] Format-Chart - Formats output as a table with a chart colum PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46