Mimi Maryami|Single|81384482360|3602054303800001|4300018742|004204300018742|643100|APN0NCC1A3|03/02/2023|03/01/2024|Jl KP panyembir RT 001/001 Serdang Kulon Panongan Tangerang 15710|Serdang Kulon|15710|36944181|NEW| 2.0|Toko Kharisma "88"|Tangerang|AMAN_PPI
Here a sample from my CSV file, and I want to remove double quotes from |Toko Kharisma "88"|
$Path = "D:\WORK\Task - Script\20221010 - AJK - ITPRODIS380 - upload file csv ke sql server\csvfile\"
$file_name = "testing.csv"
$csv_file = $Path $file_name
(Get-Content $csv_file) -replace '^"(.*?)"$', '$1' |
Set-Content $csv_file
I have tried using the following code, but it still doesn't work, I just want to update it not create a new file
CodePudding user response:
This can do the trick, tested on my side:
$CSVFile = 'E:\temp\CSV1.csv'
$TempFile = "$Env:Temp\Temp.csv"
$(GC $CSVFile) -Replace '\x22','' | Set-Content $TempFile
#If you really want to replace the original afterwards, then you can over-write it like this:
Move-Item -Path $TempFile -Destination $CSVFile -Force
GC $CSVFile