0

I have a csv file with data looking like this.

Div,Date,HomeTeam,AwayTeam,FTHG,FTAG,FTR,HTHG,HTAG,HTR
I1,20/08/16,Juventus,Fiorentina,2,1,H,1,0,H
I1,20/08/16,Roma,Udinese,4,0,H,0,0,D
I1,21/08/16,Atalanta,Lazio,3,4,A,0,3,A
I1,21/08/16,Bologna,Crotone,1,0,H,0,0,D

I am trying to export first six columns like below to a new csv file.

Div,Date,HomeTeam,AwayTeam,FTHG,FTAG
I1,20/08/16,Juventus,Fiorentina,2,1
I1,20/08/16,Roma,Udinese,4,0
I1,21/08/16,Atalanta,Lazio,3,4
I1,21/08/16,Bologna,Crotone,1,0

I am using the following powershell command.

Import-Csv $infile -DeLimiter ","|
Select'Div','Date','HomeTeam','AwayTeam','FTHG','FTAG'| 
Export-Csv $trimfile -DeLimiter "," -NoTypeInformation

But my output csv file looks like this

"Div","Date","HomeTeam","AwayTeam","FTHG","FTAG"
"I1","20/08/16","Juventus","Fiorentina","2","1"
"I1","20/08/16","Roma","Udinese","4","0"
"I1","21/08/16","Atalanta","Lazio","3","4"
"I1","21/08/16","Bologna","Crotone","1","0"

The no.of columns are much higher in the actual file. Simplified it here. What am I doing wrong?

3
  • What's wrong? The quotes? 99% of csv-capable Readers understands and removes them.. Commented Apr 24, 2017 at 6:58
  • yes. Then I have to import the data into sqlite, where the qoutes appear in all fields. Commented Apr 24, 2017 at 7:05
  • and if you have a "," into string? Quote are necessary Commented Apr 24, 2017 at 9:10

1 Answer 1

3

Try with this code :

Import-Csv $infile -DeLimiter "," | 
Select-Object 'Div','Date','HomeTeam','AwayTeam','FTHG','FTAG' | 
ConvertTo-Csv -NoTypeInformation | 
ForEach-Object { $_ -replace '"', ""} | 
Out-File $trimfile
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.