Solved

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

Posted on 2015-01-13
1
88 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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

20 Experts available now in Live!

Get 1:1 Help Now