Skip to content

Instantly share code, notes, and snippets.

@shiitake
Created March 6, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiitake/362765041073ce768706b6eb724dd20d to your computer and use it in GitHub Desktop.
Save shiitake/362765041073ce768706b6eb724dd20d to your computer and use it in GitHub Desktop.
PowerShell- Remove double quotes from csv files in a directory.
$currentPath = (get-item -Path ".\" -Verbose).FullName
$outputPath = Join-Path $currentPath "fixed"
if (!(Test-Path $outputPath)) {
New-Item -ItemType Directory -Path $outputPath | Out-Null
}
$count = 0
Get-ChildItem $currentPath -Filter "*.csv" |
Foreach-Object {
$content = Get-Content $_.FullName
#remove double quotes at the start and end of line
$startAndEnd = [regex]("^`"|`"$")
#remove double quotes before and after commas
$aroundCommas = [regex]("`",`"|`",|,`"")
#filter and save content to a new file
$content | Foreach-Object {$_ -replace $startAndEnd, ''`
-replace $aroundCommas, ','} `
| Set-Content ($outputPath + "\" + $_.Name)
$count++
}
Write-Host "Fixed file count: "$count
@Trones21
Copy link

This caused my columns to become misaligned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment