header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
Delete double quotes just for header
Last Post 04 Jul 2012 02:18 PM by jordan49. 6 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
jordan49User is Offline
New Member
New Member
Posts:11
Avatar

--
03 Jul 2012 11:55 AM
    Hello,

    I'm looking a way to delete double quotes caractere in csv, but only for the first line...
    If i'm using this script : (Get-Content c:\users.csv) -replace('"','') | Out-File C:\users.csv -force it's work but for all csv lines...

    For exemple, CSV looks like :

    "Name","Lastname"
    "Jordan" ,"Durand"

    I would like to have :

    Name,Lastname
    "Jordan" ,"Durand"

    Can you help me  please ? 
    Thanks.
    EBGreenUser is Offline
    Veteran Member
    Veteran Member
    Posts:1276
    Avatar

    --
    03 Jul 2012 12:01 PM
    I'm curious why you would want to do this? The CSV snippet that you posted meets the CSV standard. Regardless here is one way:

    $replace = $true
    Get-Content c:\users.csv | %{if($replace){$replace = $false; $_ -replace '"', ''}else{$_}} | Out-file C:\users.csv -force
    "Look Ma...no strings!"
    jordan49User is Offline
    New Member
    New Member
    Posts:11
    Avatar

    --
    03 Jul 2012 01:18 PM
    I need to do that because the csv file is used with another script to populate SharePoint contact list. If the double quotes are not deleted for the header, the list is populated by blank contact. Without quotes, it's works.
    I have tested your script, but the csv become blank (all content was deleted.)..
    RiffyRiotUser is Offline
    Basic Member
    Basic Member
    Posts:329
    Avatar

    --
    03 Jul 2012 04:31 PM
    The method EBGreen posted works for me.
    Here's another way...

    ## create sample file
    $mynames=@"
    "Name","Lastname"
    "Jordan","Durand"
    "@
    $mynames | Out-File 'c:\temp\names.csv'

    $mynames=get-content 'c:\temp\names.csv'
    $mynames[0]=$mynames[0] -replace '"',''
    $mynames | set-content 'c:\temp\names.csv'
    Rule #1: You should only use Format-Table as the final command in the pipeline and only when you're not using the output for anything else
    jordan49User is Offline
    New Member
    New Member
    Posts:11
    Avatar

    --
    04 Jul 2012 12:17 AM
    Hello, thanks RiffyRiot but i can't edit my CSV file so is there another way to do that ?
    I have try againt the script of EBGreen but my CSV file becomes empty...
    RiffyRiotUser is Offline
    Basic Member
    Basic Member
    Posts:329
    Avatar

    --
    04 Jul 2012 01:55 PM
    This script...

    $mynames=get-content 'c:\temp\names.csv'
    $mynames[0]=$mynames[0] -replace '"',''
    $mynames | set-content 'c:\temp\names.csv'

    does pretty much the same as what's in your first post...

    (Get-Content c:\users.csv) -replace('"','') | Out-File C:\users.csv -force

    but only for the first line of the file.

    Both are 'editing my CSV file'

    What do you mean 'I can't edit my CSV file'?
    Rule #1: You should only use Format-Table as the final command in the pipeline and only when you're not using the output for anything else
    jordan49User is Offline
    New Member
    New Member
    Posts:11
    Avatar

    --
    04 Jul 2012 02:18 PM
    Thanks RiffyRiot, it works now ;)
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer