Solved

Powershell: How to remove " from a csv ?

Posted on 2013-06-14
7
2,069 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 41

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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 41

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

18 Experts available now in Live!

Get 1:1 Help Now