Solved

Powershell: How to remove " from a csv ?

Posted on 2013-06-14
7
2,838 Views
Last Modified: 2013-06-14
Hi, I have the following csv and would like to remove the double quotes and create a new csv with the quotes removed.
Now:
fullname,club,clock
"Altidore, Jozy",AZ Alkmaar (Netherlands),3000
"Beasley, DaMarcus",Puebla (Mexico),3001
"Besler, Matt",Sporting Kansas City,3002
Expected:
Lastname,firstname,club,clock
Altidore,Jozy,AZ Alkmaar (Netherlands),3000
Beasley,DaMarcus,Puebla (Mexico),3001
Besler,Matt,Sporting Kansas City,3002

I tried the following but get an error:
$File = Import-Csv "SoccerPlayers_Original.csv"
foreach ($csv_user in $file) { $new_csv_user = $csv_user -replace "["]" }

Open in new window

0
Comment
Question by:namerg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 43

Expert Comment

by:Amit
ID: 39247970
Open file in excel, press control + F, click on Replace tab, in find what type " in replace with leave it blank, hit replace all you are done.
0
 

Author Comment

by:namerg
ID: 39247978
And in powershell ?
0
 

Author Comment

by:namerg
ID: 39247991
I think i got it.
$file = "C:\SoccerPlayers_Original.csv"
(Get-Content $File) | Foreach-Object {$_ -replace "`"", ""} | Set-Content $File
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 43

Expert Comment

by:Amit
ID: 39247992
Great...
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39248020
Does your code change the headers?
Try..
Import-Csv "C:\SoccerPlayers_Original.csv" | Select @{N="Lastname";E={($_.fullname -split ",")[0].Trim()}},@{N="firstname";E={($_.fullname -split ",")[1].Trim()}},club,clock | Export-Csv Result.csv -NoTypeInformation

Open in new window

0
 

Author Comment

by:namerg
ID: 39248058
JAJAJ....nooooo
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39248086
:-)..
0

Featured Post

Veeam gives away 10 full conference passes

Veeam is a VMworld 2017 US & Europe Platinum Sponsor. Enter the raffle to get the full conference pass. Pass includes the admission to all general and breakout sessions, VMware Hands-On Labs, Solutions Exchange, exclusive giveaways and the great VMworld Customer Appreciation Part

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question