Page 1 of 1

Replace Double Quotes in text files

Posted: 31 Mar 2015 22:51
by etniesbg
Hello guys,

I am new here.
Can someone help me with this.

I have multiple .txt files with data looking something like this:
11 1111 11 1111
""1"" ""22"" ""[23]"" ""5.11""

file names are something like:

filename2341245_32142134.txt
filename24432151_3412354.txt

and etc.


I tried the code below, but the problem I faced was that there is no way to use wildcards for file names.

Code: Select all

@echo off
REM This is to make your program pretty when run

setlocal EnableDelayedExpansion
REM This is to allow for variable editing within the for loop

for /f "delims=" %%A in (flatFILE.txt) do (
REM This loops through each line in flatFILE.txt
REM and performs everything within () to the line
REM which is held in %%A

    set a=%%A
    echo !a:"=! >>newFile.txt
    REM this adds the line to newFile.txt replacing every instance of " with no character
)


thanks

Re: Replace Double Quota batch file

Posted: 01 Apr 2015 02:05
by foxidrive

Re: Replace Double Quota batch file

Posted: 01 Apr 2015 05:55
by Squashman
I am assuming you want to process multiple files located in a directory. In that case you can wrap your existing FOR /F command in base FOR command and use the TOKEN from the first FOR command in your FOR /F.
And yes, the FOR command will support wildcards for file names.

Re: Replace Double Quota batch file

Posted: 01 Apr 2015 17:01
by foxidrive
On reading the actual code and figuring out the subject line (it's edited now), I see what the unasked question is too. :)

This should remove all double quote characters (hex 22) from the text files in the current directory:

Code: Select all

@echo off
for /f "delims=" %%a in ('dir *.txt /b /a-d ') do (
   echo processing "%%a"
   call jrepl "\x22" "" /x /f "%%a" /O -
)




This uses a native Windows batch script called Jrepl.bat (by dbenham)
- download from: https://www.dropbox.com/s/4otci4d4s8x5ni4/Jrepl.bat
and it can also be found here: viewtopic.php?f=3&t=6044


Place it in the same folder as the batch file, or in a folder that is on the system path.

Windows blocks various downloaded files to keep you on your toes...
it can be unblocked by this step:

* Right click the batch file
* select the "Properties" entry
* and click "Unblock"