• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

converting CSV comma to csv semi-column

T

Teddy

#1
HI !

I am trying to convert a csv file with comma to a csv file with
semi-column.

I tried import-csv, export-csv, convert from...

It didn't work. I don't understand. I'm an idiot !

What would be the best way ?

can you help me please?

thanks
 

My Computer

M

Marco Shaw [MVP]

#2
You can only do this with PowerShell v2:
PS>import-csv input.csv|export-csv -delim ";" output.csv

PowerShell v1 doesn't support the -Delimiter parameter.

Marco

"Teddy" <noreply@newsgroup> wrote in message
news:4be52db9$0$15666$426a74cc@newsgroup

> HI !
>
> I am trying to convert a csv file with comma to a csv file with
> semi-column.
>
> I tried import-csv, export-csv, convert from...
>
> It didn't work. I don't understand. I'm an idiot !
>
> What would be the best way ?
>
> can you help me please?
>
> thanks
>
>
 

My Computer

T

Teddy

#3
"Marco Shaw [MVP]" <marco.shaw@newsgroup_SPAMgmail.com> a écrit dans le message de
news:uX4K%23vp7KHA.5808@newsgroup

> You can only do this with PowerShell v2:
> PS>import-csv input.csv|export-csv -delim ";" output.csv
>
> PowerShell v1 doesn't support the -Delimiter parameter.
>
> Marco

thank you Marco, but it doesn't work too.

Import-Csv: Can not process argument, the argument value "name" is not
valid. Change the value of the argument "name" and rerun the operation. At
line: 1 Character: 11
+ import-csv <<<< input.csv|export-csv -delim ";" output.csv
+ CategoryInfo : InvalidArgument: (:) [Import-Csv],
PSArgumentExc
eption
+ FullyQualifiedErrorId :
Argument,Microsoft.PowerShell.Commands.ImportCsv
Command

where input.csv is real file I rename from excel csv one
I run powershell 2 under W7
 

My Computer

L

Larry__Weiss

#4
On 5/8/2010 9:20 AM, Teddy wrote:

> "Marco Shaw [MVP]"

>> You can only do this with PowerShell v2:
>> PS>import-csv input.csv|export-csv -delim ";" output.csv
>> PowerShell v1 doesn't support the -Delimiter parameter.
>>
>
> thank you Marco, but it doesn't work too.
> Import-Csv: Can not process argument, the argument value "name" is not
> valid. Change the value of the argument "name" and rerun the operation.
> At line: 1 Character: 11
> + import-csv <<<< input.csv|export-csv -delim ";" output.csv
> + CategoryInfo : InvalidArgument: (:) [Import-Csv], PSArgumentExc
> eption
> + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.ImportCsv
> Command
> where input.csv is real file I rename from excel csv one
> I run powershell 2 under W7
Reading from

http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/

I learn that the error you are getting is related to the content
of your file input.csv

Be sure that input.csv is a valid CSV formatted file.

That article states that even Excel can produce a CSV file that
causes this error.

- Larry
 

My Computer

T

Teddy

#5

>
> Reading from
>
> http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/
>
> I learn that the error you are getting is related to the content
> of your file input.csv
>
> Be sure that input.csv is a valid CSV formatted file.
>
> That article states that even Excel can produce a CSV file that
> causes this error.
>
> - Larry
thank you Larry, I think it's right but ...

I tried with an other file, now input.csv only contain :
test1,test2,test3,test4

when I run import-csv input.csv|export-csv -delim ";" output.csv

there is no more error, but output file is empty !!!
I am desapointed !
It's the 1st time I use powershell.

I tried :

PS C:\temp> $data = get-content input.csv
PS C:\temp> $p
PS C:\temp> $data
test1,test2,test3,test4

so input.csv is ok
 

My Computer

L

Larry__Weiss

#6
On 5/8/2010 10:08 AM, Teddy wrote:

>> Reading from
>> http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/
>> I learn that the error you are getting is related to the content
>> of your file input.csv
>> Be sure that input.csv is a valid CSV formatted file.
>> That article states that even Excel can produce a CSV file that
>> causes this error.
>>
>
> thank you Larry, I think it's right but ...
> I tried with an other file, now input.csv only contain :
> test1,test2,test3,test4
> when I run import-csv input.csv|export-csv -delim ";" output.csv
> there is no more error, but output file is empty !!!
> I am desapointed !
> It's the 1st time I use powershell.
> I tried :
> PS C:\temp> $data = get-content input.csv
> PS C:\temp> $p
> PS C:\temp> $data
> test1,test2,test3,test4
> so input.csv is ok
>
For the simplest CSV files it turns out to be more complicated.
You have to provide column header captions via a parameter.
And, if you wish to create a simple CSV as output you have to do
some post-processing.

With import.csv containing

test1,test2,test3,test4

Try these PowerShell commands

import-csv -header "col1","col2","col3","col4" input.csv |
export-csv -delimiter ';' output.csv
$a = (get-content output.csv)
$a[2..($a.count - 1)] | out-file -encoding ASCII output.csv

- Larry
 

My Computer

T

Teddy

#7
"Larry__Weiss" <lfw@newsgroup> a écrit dans le message de
news:%23K$%236Vt7KHA.420@newsgroup

> On 5/8/2010 10:08 AM, Teddy wrote:

>>> Reading from
>>> http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/
>>> I learn that the error you are getting is related to the content
>>> of your file input.csv
>>> Be sure that input.csv is a valid CSV formatted file.
>>> That article states that even Excel can produce a CSV file that
>>> causes this error.
>>>
>>
>> thank you Larry, I think it's right but ...
>> I tried with an other file, now input.csv only contain :
>> test1,test2,test3,test4
>> when I run import-csv input.csv|export-csv -delim ";" output.csv
>> there is no more error, but output file is empty !!!
>> I am desapointed !
>> It's the 1st time I use powershell.
>> I tried :
>> PS C:\temp> $data = get-content input.csv
>> PS C:\temp> $p
>> PS C:\temp> $data
>> test1,test2,test3,test4
>> so input.csv is ok
>>
>
> For the simplest CSV files it turns out to be more complicated.
> You have to provide column header captions via a parameter.
> And, if you wish to create a simple CSV as output you have to do
> some post-processing.
>
> With import.csv containing
>
> test1,test2,test3,test4
>
> Try these PowerShell commands
>
> import-csv -header "col1","col2","col3","col4" input.csv |
> export-csv -delimiter ';' output.csv
> $a = (get-content output.csv)
> $a[2..($a.count - 1)] | out-file -encoding ASCII output.csv
>
> - Larry
thank you Larry, your PowerShell commands works well !!

Now, I should have to see what it is wrong with my real file exported by
excel. it doesn't work no more.
 

My Computer

L

Larry__Weiss

#8
On 5/8/2010 1:09 PM, Teddy wrote:

> "Larry__Weiss"

>> For the simplest CSV files it turns out to be more complicated.
>> You have to provide column header captions via a parameter.
>> And, if you wish to create a simple CSV as output you have to do
>> some post-processing.
>> With import.csv containing
>> test1,test2,test3,test4
>> Try these PowerShell commands
>> import-csv -header "col1","col2","col3","col4" input.csv |
>> export-csv -delimiter ';' output.csv
>> $a = (get-content output.csv)
>> $a[2..($a.count - 1)] | out-file -encoding ASCII output.csv
>>
>
> thank you Larry, your PowerShell commands works well !!
> Now, I should have to see what it is wrong with my real file exported by
> excel. it doesn't work no more.
>
http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/

suggests it is usually some trailing (right-most) extraneous data.

- Larry
 

My Computer

T

Teddy

#9
"Larry__Weiss" <lfw@newsgroup> a écrit dans le message de
news:u7Egatt7KHA.720@newsgroup

>
> On 5/8/2010 1:09 PM, Teddy wrote:

>> "Larry__Weiss"

>>> For the simplest CSV files it turns out to be more complicated.
>>> You have to provide column header captions via a parameter.
>>> And, if you wish to create a simple CSV as output you have to do
>>> some post-processing.
>>> With import.csv containing
>>> test1,test2,test3,test4
>>> Try these PowerShell commands
>>> import-csv -header "col1","col2","col3","col4" input.csv |
>>> export-csv -delimiter ';' output.csv
>>> $a = (get-content output.csv)
>>> $a[2..($a.count - 1)] | out-file -encoding ASCII output.csv
> >>
>>
>> thank you Larry, your PowerShell commands works well !!
>> Now, I should have to see what it is wrong with my real file exported by
>> excel. it doesn't work no more.
>>
>
> http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/
>
> suggests it is usually some trailing (right-most) extraneous data.
>
> - Larry
>
thank you, I'll take a look.

Teddy
 

My Computer

T

Teddy

#10
"Larry__Weiss" <lfw@newsgroup> a écrit dans le message de
news:u7Egatt7KHA.720@newsgroup

>
> On 5/8/2010 1:09 PM, Teddy wrote:

>> "Larry__Weiss"

>>> For the simplest CSV files it turns out to be more complicated.
>>> You have to provide column header captions via a parameter.
>>> And, if you wish to create a simple CSV as output you have to do
>>> some post-processing.
>>> With import.csv containing
>>> test1,test2,test3,test4
>>> Try these PowerShell commands
>>> import-csv -header "col1","col2","col3","col4" input.csv |
>>> export-csv -delimiter ';' output.csv
>>> $a = (get-content output.csv)
>>> $a[2..($a.count - 1)] | out-file -encoding ASCII output.csv
> >>
>>
>> thank you Larry, your PowerShell commands works well !!
>> Now, I should have to see what it is wrong with my real file exported by
>> excel. it doesn't work no more.
>>
>
> http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/
>
> suggests it is usually some trailing (right-most) extraneous data.
>
> - Larry
>
Hi Larry

you are right !

The error I got is related to the empty value between commas !

no way to change this because the file is generate automaticaly with a
sofware under visual basic !

I tried to change "," to ";"
with Foreach{$_.Replace(",", ";")}
but when there is a value like "125,10" the result is "125;10"
in France, "," is the separate for decimal instead of point so we write
125,10 instead of 125.10
thank you

Teddy
 

My Computer

H

Hans Dingemans

#11
Not sure this has to do with the initial question, but note that Export-CSV
and Import-CSV also have a -UseCulture parameter

PS> get-culture

LCID Name DisplayName
---- ---- -----------
1043 nl-NL Dutch (Netherlands)

PS> (Get-Culture).TextInfo.ListSeparator
;
PS>

Get-Process | Export-Csv c:\processes.csv; Invoke-Item c:\processes.csv
#provided Excel is present

Above pipe results in a spreadsheet with comma-separated strings in Column
A. Probably not what you want.

Get-Process | Export-Csv c:\processes.csv -UseCulture; Invoke-Item
c:\processes.csv # note the new 2.0 UseCulture parameter

This is the sheet you want, with columns for ALL process properties; not
just the eight columns you know in PS console.

From the (2.0) help file:

-UseCulture
Use the list separator for the current culture as the item delimiter. The
default is a comma (,).

This parameter is very useful in scripts that are being distributed to users
worldwide. To find the list separator for a culture, use the following
command: (Get-Culture).TextInfo.ListSeparator.

Type info above the heading can be suppressed by -NoTypeInformation
parameter.

HtH,
Hans



"Teddy" <noreply@newsgroup> schreef in bericht
news:4be52db9$0$15666$426a74cc@newsgroup

> HI !
>
> I am trying to convert a csv file with comma to a csv file with
> semi-column.
>
> I tried import-csv, export-csv, convert from...
>
> It didn't work. I don't understand. I'm an idiot !
>
> What would be the best way ?
>
> can you help me please?
>
> thanks
>
>
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)