Replacing Double Quotes using BatchSubstitute

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
idbcat
Posts: 2
Joined: 04 Mar 2015 10:47

Replacing Double Quotes using BatchSubstitute

#1 Post by idbcat » 04 Mar 2015 10:52

Hello,

What is the magic parameter to use in BatchSubstitute to replace double-quotes (") in a string? I have tried all manner of escape characters, and I cannot replace the double-quotes throughout my file.

Thanks,
Steve

jeb
Expert
Posts: 1063
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Replacing Double Quotes using BatchSubstitute

#2 Post by jeb » 04 Mar 2015 12:27

Hi Steve,

I suppose something like this should work.

Code: Select all

@echo off
set myVar=Text with "quotes"
set newVar=%myVar:"=#%
echo %newVar%

idbcat
Posts: 2
Joined: 04 Mar 2015 10:47

Re: Replacing Double Quotes using BatchSubstitute

#3 Post by idbcat » 04 Mar 2015 12:52

I am trying to do something like this:

BatchSubstitute.bat """" "" filein.txt > fileout.txt

I have data similar to this:

"Red","Blue",1,2,3,"Green"

And, want those double-quotes to be replaced with empty strings, i.e.

Red,Blue,1,2,3,Green

The """" above doesn't seem to do anything. I have tried things like "\"\"", et al, with no luck.

Thanks,
Steve

jeb
Expert
Posts: 1063
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Replacing Double Quotes using BatchSubstitute

#4 Post by jeb » 04 Mar 2015 14:43

In this case you should switch to JREPL.bat from dbenham.

It's much more powerful than BatchSubstitute.bat and can handle such cases

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Replacing Double Quotes using BatchSubstitute

#5 Post by Squashman » 04 Mar 2015 15:29

JREPL is the way to go...
But if you always knew how many delimited fields you were working with you could easily do it with a FOR /F command as long as none of the fields are empty.

Code: Select all

FOR /F "TOKENS=1-6 DELIM=," %%G IN (myfile.txt) DO >>newfile.txt ECHO %%~G,%%~H,%%~I,%%J,%%~K,%%~L

Yury
Posts: 115
Joined: 28 Dec 2013 07:54

Re: Replacing Double Quotes using BatchSubstitute

#6 Post by Yury » 04 Mar 2015 15:31

Code: Select all

@echo off

set "in=filein.txt"
set "out=fileout.txt"

for /f %%i in ('^<"%in%" find/c /v ""') do<"%in%">"%out%" (
 for /l %%j in (1 1 %%i) do (
  set/p "x="
  if defined x (cmd/v/c echo(!x:^"=!) else (echo()
  set "x="
  )
 )

exit/b

Post Reply