header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Export-csv - export without double quotes around strings containing spaces?
Last Post 09 Mar 2010 08:23 AM by PoSherLife. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
seaJhawkUser is Offline
Basic Member
Basic Member
Posts:191
Avatar

--
19 Sep 2009 04:39 AM

    Is it possible to call export-csv and have it not put double quotes around strings that contain spaces?

    Thanks,
    Chris

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    20 Sep 2009 06:27 AM
    No, that's the default behaviour of export-csv. It will put double quotes for any value or property names (header) that contain spaces.

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    pchapmanUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    09 Mar 2010 08:03 AM
    ### Writes CSV, but stupid export-csv does so with quotes around every field
    $temp | export-csv -notype "d:\reports\name_of_file.csv"

    ### Reads the output from export-csv, gets rid of the quotes, and rewrites the file
    $text = gc "d:\reports\name_of_file.csv"
    $text = $text -replace('"','')
    $final = [String]::Join([Environment]::NewLine, $text)
    [System.IO.File]::WriteAllText("d:\reports\name_of_final", $final)


    it's ugly, but it will get you a .csv with no quotes.
    pchapmanUser is Offline
    New Member
    New Member
    Posts:2
    Avatar

    --
    09 Mar 2010 08:05 AM
    just for clarification, the replace statement is a single quote, double quote, single quote, comma, two single quotes.
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    09 Mar 2010 08:23 AM
    this can be simplified by:
    $file = "file.csv"
    (gc $file) -replace('"','') | Out-File $file -Force
    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer