Adjust website powershell

I found a website on the internet and i want to know if somebody can help me to put the text from my files in the website

The text from my files look like
Datum             Klant naam                             Adres           Postcode Artikelcode
-----             ----------                             -----                   -------- -----------
13-4-2015         Chao Phraya Restaurant            Nieuwmarkt 8-10 1012CR  50001  

Datum             Klant naam                             Adres                       Postcode Artikelcode  
-----             ----------                             -----                       -------- -----------  
13-4-2015         Restaurant Genki                       Reguliersdrwarsstraat 26    1017BM   26173      
13-4-2015         Restaurant Genki                       Reguliersdrwarsstraat 26    1017BM   26122    

And i want to place them like this in the website

$Data = @"
Chao Phraya Restaurant, 8-10 Nieuwmarkt 1012CR
Restaurant Genki, 26 Reguliersdrwarsstraat 1017BM
"@

Thanks for helping
Danny
LVL 6
Danny KonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Mark BullockQA EngineerCommented:
If the website is not yours, you can't put your data there.
If you can find out who runs it, perhaps you could ask them to add your listing.
Danny KonAuthor Commented:
Mark,

That is not the meaning the website is copied local check my other question
check my other open question
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28653463.html
Thanks

Danny
Mark BullockQA EngineerCommented:
Try this.

$FileIn = 'C:\Temp\EE\test.txt'
if (!(Test-Path $FileIn))
{
	Write-Error "ERROR: Input file `"$FileIn`" does not exist."
	return
}

$FileOut= 'website.html'
'$Data = @"' | Out-File $FileOut

$indexName = 18
$indexAddress = 54
$indexArticleCode = 93

Get-Content $FileIn | ? { $_ } | Select -Skip 2 |  % {
	$line = $_
	$name = $line.Substring($indexName,$indexAddress - $indexName).Trim()
	$indexPostcode = 84
	$address = $line.Substring($indexAddress, $indexPostcode - $indexAddress).Trim()
	
	$lengthAddress = $address.Length
	if ($address -match "(?<number>\d)") {
		$indexNumber = $address.indexof($Matches.number)
		$streetNumber = $address.substring($indexNumber - 1, $lengthAddress - $indexNumber + 1)
	} else {
		$indexNumber = $lengthAddress
		$streetNumber = ''
	}
	
	$street = $address.Substring(0, $indexNumber).Trim()

	if ($line.Substring($indexPostcode,1) -eq ' ') {
		$indexPostcode++
	}
	$postcode = $line.Substring($indexPostcode, $indexArticleCode - $indexPostcode).Trim()

    $name + ', ' + $streetNumber + ' ' + $street + ' ' + $postcode | Out-File -Append $FileOut
}
'"@' | Out-File -Append $FileOut

Open in new window

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Danny KonAuthor Commented:
Mark,

I get some errors on your solution,

Exception calling "Substring" with "2" argument(s): "StartIndex cannot be less than zero.
Parameter name: startIndex"
At line:24 char:3
+         $streetNumber = $address.substring($indexNumber - 1, $lengthAddress - $indexNu ...
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

Is it stil possible to change the input file C:\Temp\EE\test.txt to the first or the second directory in the question you just solved for me.
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28654761.html#a40730006 

Thanks for your help

Danny
Mark BullockQA EngineerCommented:
Yes you can change the input file pathname to whatever you want.
You can change the index positions. I think you did that for your other question.
Danny KonAuthor Commented:
Mark,

Can i change the file to a path? Can you help me a little further what you say that i have to change the index position where to put the write-host :)

Thanks

Danny
Mark BullockQA EngineerCommented:
You can change the input file pathname to whatever you want, like this.
$FileIn = 'C:\Temp\EE\First\mynewfile.txt'

Open in new window


The error you get at line 24 may be because your address begins with a number. I would need your input file to test it. You can add print statements to see the value of strings or numbers. For example add this after setting the value for $address:
$address | Write-Host

Open in new window


It's difficult to parse your file because the column positions change depending on the characters. It would be simpler if it was comma separated or pipe separated.
Danny KonAuthor Commented:
Mark,

I understand that i can change the input file but is it possible to use the  whole directory as input "C:\temp\first\" ?

I see the problem when i use the $address | Write-Host  
Do you mean with pipe separated that i have to change
this                                   @{Expression={$_.fldNaam};Label=”Klant naam”
to something like this ?  @{Expression={$_.fldNaam};Label=”Klant naam”;width=30
Is this the meaning that the next label will be $Nextlabel = 31?

Thanks for your help
 
Danny
Mark BullockQA EngineerCommented:
Here's a version which reads all input files in a folder.
$Directory = 'C:\Temp\EE\inputFiles'
$FileOut= 'websiteFiles.html'

'$Data = @"' | Out-File $FileOut

$InputFileList = [IO.Directory]::GetFiles($Directory)
foreach($FileIn in $InputFileList) {
	"Reading from " + $FileIn | Write-Host
	if (!(Test-Path $FileIn))
	{
		Write-Error "ERROR: Input file `"$FileIn`" does not exist."
		return
	}

	$indexName = 18
	$indexAddress = 54
	$indexArticleCode = 93

	Get-Content $FileIn | ? { $_ } | Select -Skip 2 |  % {
		$line = $_
		$name = $line.Substring($indexName,$indexAddress - $indexName).Trim()
		$indexPostcode = 84
		$address = $line.Substring($indexAddress, $indexPostcode - $indexAddress).Trim()
		
		$lengthAddress = $address.Length
		if ($address -match "(?<number>\d)") {
			$indexNumber = $address.indexof($Matches.number)
			$streetNumber = $address.substring($indexNumber - 1, $lengthAddress - $indexNumber + 1)
		} else {
			$indexNumber = $lengthAddress
			$streetNumber = ''
		}
		
		$street = $address.Substring(0, $indexNumber).Trim()

		if ($line.Substring($indexPostcode,1) -eq ' ') {
			$indexPostcode++
		}
		$postcode = $line.Substring($indexPostcode, $indexArticleCode - $indexPostcode).Trim()

		$name + ', ' + $streetNumber + ' ' + $street + ' ' + $postcode | Out-File -Append $FileOut
	}
}
'"@' | Out-File -Append $FileOut
"Output is in " + $FileOut | Write-Host

Open in new window

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
Mark BullockQA EngineerCommented:
Pipe separated input would look like this:
16-4-2015 0:00:00|Cafe Engel|Zeedijk 21|1012 AP|03120

Open in new window


To parse each column from each line of input you would do something like this:
$columns = $line.Split("|")
#$columns[0] is datum, $columns[1] is name, etc.

Open in new window

$Directory = 'C:\Temp\EE\inputFiles'
$FileOut= 'websiteFiles.html'

'$Data = @"' | Out-File $FileOut

$InputFileList = [IO.Directory]::GetFiles($Directory)
foreach($FileIn in $InputFileList) {
	"Reading from " + $FileIn | Write-Host
	if (!(Test-Path $FileIn))
	{
		Write-Error "ERROR: Input file `"$FileIn`" does not exist."
		return
	}

	$indexName = 18
	$indexAddress = 54
	$indexArticleCode = 93

	Get-Content $FileIn | ? { $_ } | Select -Skip 2 |  % {
		$line = $_
		$name = $line.Substring($indexName,$indexAddress - $indexName).Trim()
		$indexPostcode = 84
		$address = $line.Substring($indexAddress, $indexPostcode - $indexAddress).Trim()
		
		$lengthAddress = $address.Length
		if ($address -match "(?<number>\d)") {
			$indexNumber = $address.indexof($Matches.number)
			$streetNumber = $address.substring($indexNumber - 1, $lengthAddress - $indexNumber + 1)
		} else {
			$indexNumber = $lengthAddress
			$streetNumber = ''
		}
		
		$street = $address.Substring(0, $indexNumber).Trim()

		if ($line.Substring($indexPostcode,1) -eq ' ') {
			$indexPostcode++
		}
		$postcode = $line.Substring($indexPostcode, $indexArticleCode - $indexPostcode).Trim()

		$name + ', ' + $streetNumber + ' ' + $street + ' ' + $postcode | Out-File -Append $FileOut
	}
}
'"@' | Out-File -Append $FileOut
"Output is in " + $FileOut | Write-Host

Open in new window

Danny KonAuthor Commented:
Mark,

Works perfect ,thanks for all the explanation , its hard for me to read and understand but i am learning a lot from you(still long way to go :)

Thanks again

Danny
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
Powershell

From novice to tech pro — start learning today.