Solved

Inject CSV lines into HTML files -where am i going wrong?

Posted on 2015-01-13
1
98 Views
Last Modified: 2015-01-13
Guys, what am i doing wrong here?
I have a huge CSV file , its not delimited properly, but what i want to do is to inject each from it to an HTML file with a random name.
the script below creates one one file, properly, but loops on it (over writing it) insted of creating multiple files per line.
Can you help?

$a = Get-Content .\BigCSVFILE.csv 
$1 = get-date -f yyyy-MM-dd-hh-mm-ss
$2 = ".html"
$random = -join(48..57+65..90+97..122 | ForEach-Object {[char]$_} | Get-Random -Count 6)
foreach ($i in $a) {echo $i > $1$random$2}

Open in new window

0
Comment
Question by:PleaseAnswer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40546340
Hi,
as far as I understand the issue is that the $random variable is initialized only once. What I do not understand is your requirement: do you just need a random file name?
Because you initialize everything outside the loop and therefore the file name is static.
If you switch your code to this
$a = Get-Content .\BigCSVFILE.csv
$1 = get-date -f yyyy-MM-dd-hh-mm-ss
$2 = ".html"
foreach ($i in $a) {
$random = -join(48..57+65..90+97..122 | ForEach-Object {[char]$_} | Get-Random -Count 6)
echo $i > $1$random$2
}

Open in new window

it will work.
HTH
Rainer
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question