I want to remove the quotation marks for only the first column of my csv file with powershell
So instead of:
"Username","Identifier"
"booker12","9012"
"grey07","2070"
I want the result to be:
Username,"Identifier"
booker12,"9012"
grey07,"2070
To remove all quotation marks the code would be
Import-Csv "test.csv" | ConvertTo-CSV -NoTypeInformation | % { $_ -Replace '"', ""} | Out-File C:\CSV_Tests\test.csv -fo -en ascii
But how to remove the marks just for the first column?
Thanks!
As commented, it is recommended to install the latest PowerShell version which has a new
ConvertTo-Csv/Export-Csvcmdlets with a-quotefields.But as that appears not to be possible for your environment:
Explanation:
^marks the beginning of a line([^"]*)selects all successive characters that aren't double quotes2.For your file this means:
(Get-Content .\Test.csv)are not recommended but required if you write back to the same file.