Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell: How to remove " from a csv ?

Posted on 2013-06-14
7
Medium Priority
?
3,235 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 44

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 44

Expert Comment

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

Accepted Solution

by:
Subsun earned 2000 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Loops Section Overview
Screencast - Getting to Know the Pipeline

824 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