export content to csv file vb script

I have following file with extension (olu) --> really mean txt file

[element]
Type=OU Document with type

[Docs]
1=\ft\ou\ds\comb\5623589556536.TIF
2=\ft\ou\ds\comb\5623589556586.TIF

[Indices.1]
account_number=9999999
first_name=test user
address=0
sub_class=OUT
linux_date=20000630
bentch_date=  /  /  
mod_acct_num=



[Indices.2]
account_number=9999999
first_name=test user
address=0
sub_class=OUT
linux_date=20000630
bentch_date=  /  /  
mod_acct_num=

Open in new window

I am looking for vb script to parse through *.olu file and export following information out in csv file
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
| Filename | element-type          | Docs.1                           | Docs.2                           | Indices.1-account_number | Indices.1-first_name | Indices.1-address | Indices.1-sub_class | Indices.1-linux_date | Indices.1-bentch_date | Indices.2-mod_acct_num | *** |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
| *.olu    | OU Document with type | \ft\ou\ds\comb\5623589556536.TIF | \ft\ou\ds\comb\5623589556586.TIF |9999999                   |    test user         |          0        |        OUT          |      20000630        |     /  /              |                        |     |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
|          |                       |                                  |                                  |                          |                      |                   |                     |                      |                       |                        |     |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+
|          |                       |                                  |                                  |                          |                      |                   |                     |                      |                       |                        |     |
+----------+-----------------------+----------------------------------+----------------------------------+--------------------------+----------------------+-------------------+---------------------+----------------------+-----------------------+------------------------+--+

Open in new window

LVL 5
CalmSoulAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
How many Indices.# sections can there be?
0
oBdACommented:
You didn't give a whole lot of information about how the indices are related, but my guess is that the numeric keys in the Docs section will end up being the numbers in the "Indices" sections.
Based on that, here's a Powershell script that should do the trick.
I took the liberty of reformatting the default output; it will generate one row per index found, with the respective properties.
If you really want the single row you described, call the script with the -SingleRow argument.
You pass it the olu file as first argument, and optionally the path to the export csv file as second argument; if this argument is empty, the script will write the results to the pipeline.
Examples:
.\Import-Olu.ps1 -Path C:\Temp\test.olu
.\Import-Olu.ps1 -Path C:\Temp\test.olu -ExportPath C:\Temp\test.csv -SingleRow
#Requires -Version 2
[CmdletBinding()]
Param(
	[Parameter(Mandatory=$True, Position=0)][ValidateNotNull()]
	[string]$Path,
	[Parameter(Mandatory=$False)]
	[string]$ExportPath,
	[Parameter(Mandatory=$False)]
	[switch]$SingleRow
)
If (-Not (Test-Path -Path $Path)) {
	Throw "Import file '$Path' not found!"
}
If ($ExportPath) {
	$ExportFolder = Split-Path -Path $ExportPath -Parent
	If (-Not (Test-Path -Path $ExportFolder -PathType Container)) {
		Throw "Export folder '$ExportFolder' not found!"
	}
}
$olu = @{}
$Section = $Null
Switch -File $Path -RegEx {
	"\A\s*\[(?<Section>.+)\].*\Z" {
		$Section = $Matches["Section"]
		$olu[$Section] = @{}
	}
	"\A\s*(?<Key>[^;].*?)\s*=\s*(?<Value>.*?)\s*\Z" {
		If ($Section) {
			$olu[$Section][$Matches["Key"]] = $Matches["Value"]
		} Else {
			"Ignored line outside a section: <$_>" | Write-Warning
		}
	}
	default {
		If ($_.Trim().Length -gt 0) {
			"Ignored commented or incorrectly formatted line: <$_>" | Write-Warning
		}
	}
}
$PropertyList = @("account_number", "first_name", "address", "sub_class", "linux_date", "bentch_date", "mod_acct_num")
If ($SingleRow) {
	$Results = New-Object -TypeName PSObject
	Add-Member -InputObject $Results -MemberType "NoteProperty" -Name "FileName" -Value (Split-Path -Path $Path -Leaf)
	Add-Member -InputObject $Results -MemberType "NoteProperty" -Name "element-type" -Value $Olu.element.Type
	ForEach ($Index In $Olu.Docs.Keys) {
		Add-Member -InputObject $Results -MemberType "NoteProperty" -Name "Docs.$Index" -Value $Olu.Docs.$Index
	}
	ForEach ($Index In ($Olu.Docs.Keys | Sort-Object)) {
		ForEach ($Property In $PropertyList) {
			Add-Member -InputObject $Results -MemberType "NoteProperty" -Name "Indices.$Index-$Property" -Value $Olu."Indices.$Index".$Property
		}
	}
} Else {
	$Results = @()
	ForEach ($Index In ($Olu.Docs.Keys | Sort-Object)) {
		$Result = New-Object -TypeName PSObject
		Add-Member -InputObject $Result -MemberType "NoteProperty" -Name "FileName" -Value (Split-Path -Path $Path -Leaf)
		Add-Member -InputObject $Result -MemberType "NoteProperty" -Name "element-type" -Value $Olu.element.Type
		Add-Member -InputObject $Result -MemberType "NoteProperty" -Name "Index" -Value $Index
		Add-Member -InputObject $Result -MemberType "NoteProperty" -Name "Document" -Value $Olu.Docs.$Index
		ForEach ($Property In $PropertyList) {
			Add-Member -InputObject $Result -MemberType "NoteProperty" -Name $Property -Value $Olu."Indices.$Index".$Property
		}
		$Results += $Result
	}
}
If ($ExportPath) {
	$Results | Export-Csv -Path $ExportPath -NoTypeInformation
} Else {
	$Results | Write-Output
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.