Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 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