1

My file is tab separated file(TSV) with 5 columns
I have local drive path on my first column but each image name from path contains double quotes.

Path
C:\Users\magoo\"flower.jpg"
C:\Users\magoo\"flower2.jpg"

Code I tried but I am not able to remove double quotes.

@ECHO Off  
SETLOCAL  
(  
FOR /f "usebackqtokens=1* delims=" %%a IN (input.csv) DO ECHO %%~a,%%b  
)>output.csv  
GOTO :EOF  
2
  • If it is a one-time job only, open the CSV with a text editor and search/replace. Much easier. – LPChip Sep 13 '19 at 18:50
  • 1
    This is not a one time job.I want to automate this process – magoosh Sep 13 '19 at 18:52
0

If you have access to a linux based system, i would recommend using sed :

sed -i 's/"//g' filename

If not, this article here seems to be pointing in the right direction, but am no batch expert myself : https://www.robvanderwoude.com/bht.php#Strip

PowerShell alternative :

(Get-Content C:\Tess.txt) | ForEach-Object { $_ -replace '"' } > C:\Tess.txt
1
  • sed is potentially available on Windows via GnuWin32 and other, similar projects. – Anaksunaman Sep 15 '19 at 21:47
0

You can give a try with this code for testing :

@echo off
Title Replace Double Quotes into a Variable
Setlocal EnableDelayedExpansion
set Var1=C:\Users\magoo\"flower.jpg"
echo Variable Var1 with quotes !Var1!
pause
:::::::::::::::::::::::::::::::::::::::::
Call :Dequote !Var1! NewVar1
echo New Variable NewVar1 without quotes !NewVar1!
pause
:::::::::::::::::::::::::::::::::::::::::
set Var2=C:\Users\magoo\"flower2.jpg"
echo Variable Var2 with quotes !Var2!
pause
:::::::::::::::::::::::::::::::::::::::::
Call :Dequote !Var2! NewVar2
echo New Variable NewVar2 without quotes !NewVar2!
:::::::::::::::::::::::::::::::::::::::::
pause
Exit
::::::::::::Function DeQuote:::::::::::::
:Dequote <Var> <NewVar to Set>
set MyString=%1
set StrToFind="
set NewStr=
set %2=!MyString:%StrToFind%=%NewStr%!
Exit /b
:::::::::::::::::::::::::::::::::::::::::

Edit : In your case you can try something like that :

@echo off
Title Replace Double Quotes into a Variable
Setlocal EnableDelayedExpansion
(
FOR /f "delims=, tokens=1-5" %%a IN ('Type input.csv') DO (
    Set "MyVar1=%%a"
    Rem We dequote the variable MyVar1 and we set it to a new on NewVar1
    Call :Dequote !MyVar1! NewVar1
    echo !NewVar1!,%%b,%%c,%%d,%%e
    )
)>output.csv
Pause & Exit
::::::::::::Function DeQuote:::::::::::::
:Dequote <OldVar> <NewVar to Set>
set MyString=%1
set StrToFind="
set NewStr=
set %2=!MyString:%StrToFind%=%NewStr%!
Exit /b
:::::::::::::::::::::::::::::::::::::::::

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.