Windows Vista Forums

converting CSV comma to csv semi-column

  1. #1


    Teddy Guest

    converting CSV comma to csv semi-column

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

  2.   


  3. #2


    Marco Shaw [MVP] Guest

    Re: converting CSV comma to csv semi-column

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

  4. #3


    Teddy Guest

    Re: converting CSV comma to csv semi-column


    "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 System SpecsSystem Spec

  5. #4


    Larry__Weiss Guest

    Re: converting CSV comma to csv semi-column

    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/...ort-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 System SpecsSystem Spec

  6. #5


    Teddy Guest

    Re: converting CSV comma to csv semi-column


    >
    > Reading from
    >
    > http://softwareblog.morlok.net/2009/...ort-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 System SpecsSystem Spec

  7. #6


    Larry__Weiss Guest

    Re: converting CSV comma to csv semi-column

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

    >> Reading from
    >> http://softwareblog.morlok.net/2009/...ort-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 System SpecsSystem Spec

  8. #7


    Teddy Guest

    Re: converting CSV comma to csv semi-column


    "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/...ort-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 System SpecsSystem Spec

  9. #8


    Larry__Weiss Guest

    Re: converting CSV comma to csv semi-column

    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/...ort-csv-error/

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

    - Larry


      My System SpecsSystem Spec

  10. #9


    Teddy Guest

    Re: converting CSV comma to csv semi-column


    "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/...ort-csv-error/
    >
    > suggests it is usually some trailing (right-most) extraneous data.
    >
    > - Larry
    >
    thank you, I'll take a look.

    Teddy


      My System SpecsSystem Spec

  11. #10


    Teddy Guest

    Re: converting CSV comma to csv semi-column


    "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/...ort-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 System SpecsSystem Spec

Page 1 of 2 12 LastLast

converting CSV comma to csv semi-column
Similar Threads
Thread Forum
Re: Leading comma operator - What does it do, really? PowerShell
Re: Converting a Word doc to a multi-column Excel spreadsheet VB Script
Convert CSV semi-colone to comma separated PowerShell
semi-locked Vista General
do something for each token in a line separated by comma PowerShell