Solved

Powershell: How to remove " from a csv ?

Posted on 2013-06-14
7
2,250 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
Are your AD admin tools letting you down?

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 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Questions about DHCP migration 5 55
DCOM errors in Server 2016 2 24
Need help to understand PowerShell code 4 22
Office 365 Script for reporting 4 21
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

813 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

16 Experts available now in Live!

Get 1:1 Help Now