1.

Solve : How to delete double quotes from a CSV file?

Answer»

How do I delete all of the double quotes (") from a CSV file? I am using Windows 7 64-bit.setlocal enabledelayedexpansion
if exist after.csv del after.csv
for /f "delims=" %%A in (before.csv) do (
set csvline=%%A
echo !csvline:"=! >> after.csv
)That's close but here's what I'm getting. The altered line are showing on the screen, but no after.csv is created.

Example before.csv

Code: [Select]1,2,"3,",
4,5,"6,7",
Output

Code: [Select]SQLP> RemoveQuotes.bat

SQLP> setlocal enabledelayedexpansion

SQLP> if exist after.csv del after.csv

SQLP> for /F "delims=" %A in (before.csv) do (
set csvline=%A
echo !csvline:"=! >> after.csv
)

SQLP> (
set csvline=1,2,"3,",
echo !csvline:"=! >> after.csv
)
1,2,3,, >> after.csv

SQLP> (
set csvline=4,5,"6,7",
echo !csvline:"=! >> after.csv
)
4,5,6,7, >> after.csv

SQLP>It's as "close" as you are going to get. Why you aren't creating after.csv in the same folder may be a question of write permissions, or perhaps it is there and you have missed it?

I presumed you knew a bit about batch scripts, but if you don't want those screen echoes make this the first line

@echo off

That looks like an SQL Prompt?Quote from: BC_Programmer on July 12, 2012, 01:51:46 PM

That looks like an SQL Prompt?

Is that what it is? I wondered if it was a heavily nonstandard cmd.exe prompt, but your theory makes more sense.
Quote from: Salmon Trout on July 12, 2012, 01:43:40 PM
It's as "close" as you are going to get. Why you aren't creating after.csv in the same folder may be a question of write permissions, or perhaps it is there and you have missed it?

I presumed you knew a bit about batch scripts, but if you don't want those screen echoes make this the first line

@echo off

I tried the script from a PREVIOUS topic that you also wrote and had no problem generating an output file. The output is going to the same folder as the input, which is on my HARD drive. I like the echo because it tells me that the desired string is being generated in memory, but the output file is not appearing.

Unfortunately, it's been a decade or so since I used DOS regularly. I'm just trying to find a way to update my data that is faster/better than importing it to EXCEL, running a macro, then saving it back out, or writing a separate .NET app to parse the file, given the requirements I'm constrained to at the moment, a CUSTOM SQL query program at my workplace that can run DOS commands. I do appreciate your effort to help.On thing you could try is putting a drive/folder specification for the output, just to make sure it's going where you think/want it to go.Maybe you could do this (echo to console & redirect to an output file)

SQLP>RemoveQuotes.bat > after.csv

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%A in (before.csv) do (
set csvline=%%A
echo !csvline:"=!
)

That worked. Thanks!


Discussion

No Comment Found