Solved

Powershell: How to remove " from a csv ?

Posted on 2013-06-14
7
2,159 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 42

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 42

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Synchronize a new Active Directory domain with an existing Office 365 tenant
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now