Solved

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

Posted on 2015-01-13
1
89 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
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Synchronize a new Active Directory domain with an existing Office 365 tenant
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now