Last active
May 29, 2018 17:18
-
-
Save gitfvb/e608ba175ab9c4086cfff9e258cad051 to your computer and use it in GitHub Desktop.
replace delimiter in CSV files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# with parsing of csv | |
$inputfile = "Datentabelle 3.txt" | |
$outputfile = "export.csv" | |
$inputdelim = "`t" | |
$outputdelim = ',' | |
$inputenc = "UTF8" | |
$outputenc = "UTF8" | |
rm $outputfile | |
Measure-Command { | |
Get-Content $inputfile -ReadCount 1000 -Encoding $inputenc | ConvertFrom-Csv -Delimiter $inputdelim | ConvertTo-Csv -NoTypeInformation -Delimiter "," | foreach { $_ -replace '^"','' -replace "`",`"",',' -replace '"$','' } | Set-Content -Path $outputfile -Encoding $outputenc | |
} | |
# plain replacement of chars without csv parsing | |
$inputfile = "Datentabelle 4.txt" | |
$outputfile = "export.csv" | |
$inputdelim = "`t" | |
$outputdelim = ',' | |
$inputenc = "UTF8" | |
$outputenc = "UTF8" | |
rm $outputfile | |
Measure-Command { | |
Get-Content $inputfile -ReadCount 1000 -Encoding $inputenc | % { $_ -replace '^"','' -replace """`t""","," -replace '"$','' } | Set-Content -Path $outputfile -Encoding $outputenc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment