Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > PowerShell

Convert CSV semi-colone to comma separated

Reply
 
Thread Tools Display Modes
Old 04-10-2008   #1 (permalink)
Gregor
Guest
 
Posts: n/a

Convert CSV semi-colone to comma separated

Hello

I have a CSV File for import in AD

firstname;lastname;street,description
Max;Huber;Street 1;Max Huber, Street 1 >In the description, I have a
commas!

How convert the csv to comma separated

fistname,lastname,street,description
Max,Huber,Street 1,"Max Huber, Street 1"

You have an idea how this makes? For converting in comma with inverted comma
(apostrophe)

Thanks
Gregor

  Reply With Quote

Old 04-10-2008   #2 (permalink)
1337 spammer

.Joe is a splendid one to behold.Joe is a splendid one to behold.Joe is a splendid one to behold.Joe is a splendid one to behold.Joe is a splendid one to behold.Joe is a splendid one to behold.Joe is a splendid one to behold
 
.Joe's Avatar
 
Join Date: Mar 2008
Vista x86 Ultimate SP1
Posts: 806

Location: 127.0.0.1
Re: Convert CSV semi-colone to comma separated

Quote:
Gregor
View Post
Hello

I have a CSV File for import in AD

firstname;lastname;street,description
Max;Huber;Street 1;Max Huber, Street 1 >In the description, I have a
commas!

How convert the csv to comma separated

fistname,lastname,street,description
Max,Huber,Street 1,"Max Huber, Street 1"

You have an idea how this makes? For converting in comma with inverted comma
(apostrophe)

Thanks
Gregor
Gregor,

If I understand your post correctly, you want to replace a ";" with a "," (without the quotes) in a text file.

Open the file with notepad. Click on edit, click replace. Put a ; in the find what box, and put a , in the replace with box. That should make the process easier for you.

.Joe is offline   Reply With Quote
Old 04-10-2008   #3 (permalink)
Gregor
Guest
 
Posts: n/a

Re: Convert CSV semi-colone to comma separated

Hi

I would like this with PowerShell, as Service

The CSV is a extract from a other resource

Gregor

".Joe" <Joe.37nbhz@xxxxxx-mx.forums.net> wrote in message
news:Joe.37nbhz@xxxxxx-mx.forums.net...
Quote:

>
> Gregor;678678 Wrote:
Quote:

>> Hello
>>
>> I have a CSV File for import in AD
>>
>> firstname;lastname;street,description
>> Max;Huber;Street 1;Max Huber, Street 1 >In the description, I have a
>> commas!
>>
>> How convert the csv to comma separated
>>
>> fistname,lastname,street,description
>> Max,Huber,Street 1,"Max Huber, Street 1"
>>
>> You have an idea how this makes? For converting in comma with inverted
>> comma
>> (apostrophe)
>>
>> Thanks
>> Gregor
>
> Gregor,
>
> If I understand your post correctly, you want to replace a ";" with a
> "," (without the quotes) in a text file.
>
> Open the file with notepad. Click on edit, click replace. Put a ; in
> the find what box, and put a , in the replace with box. That should make
> the process easier for you.
>
>
> --
> Joe
>
> _[image:
> http://uswave.net/vistax64/joetmvx64.png] (\"http://www.vistax64.com\")_
> _*::Click_here_for_the_Vista_Forums::*
> (\"http://www.vistax64.com/index.php?referrerid=17621\")_
> _Geekbench_Score:_4050
> (\"http://browse.geekbench.ca/geekbench2/view/42901\")_
> _CPU-Z_Verified (\"http://valid.x86-secret.com/show_oc.php?id=323179\")_
> _**_
  Reply With Quote
Old 04-10-2008   #4 (permalink)
Kiron
Guest
 
Posts: n/a

Re: Convert CSV semi-colone to comma separated

Split each line from the original CSV file on each ';', if any of the split strings matches a ',' surrounded it with double quotes and join all split strings back with a ','. Then set the modified content to the same, or to another, CSV file.
Also, if your encoding is not Unicode --PowerShell's default-- pass it to Get-Content and Set-Content statements through their -Encoding parameter.

# modifying same file, using Unicode encoding
$csvFile = <path to CSV file>
set-content $csvFile (get-content $csvFile |
% {[string]::join(',', ($_.split(';') |
% {if ($_ -match ',') {"`"$_`""} else {$_}}))})

# test it
import-csv $csvFile

--
Kiron
  Reply With Quote
 
Reply

Thread Tools
Display Modes









Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48