Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Convert CSV semi-colone to comma separated

Reply
 
Old 04-10-2008   #1 (permalink)
Gregor


 
 

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


My System SpecsSystem Spec
Old 04-10-2008   #2 (permalink)


Windows 7 RC
 
 

Re: Convert CSV semi-colone to comma separated

Quote  Quote: Originally Posted by 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.
My System SpecsSystem Spec
Old 04-10-2008   #3 (permalink)
Gregor


 
 

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\")_
> _**_
My System SpecsSystem Spec
Old 04-10-2008   #4 (permalink)
Kiron


 
 

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
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: Leading comma operator - What does it do, really? PowerShell
semi-locked Vista General
do something for each token in a line separated by comma PowerShell
Escape comma in dos command from PS script PowerShell
Argument that starts with '-' and contains ':' gets separated. PowerShell


Vista Forums 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 Ltd

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