Replace Double Quotes in text files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
etniesbg
Posts: 1
Joined: 31 Mar 2015 22:43

Replace Double Quotes in text files

#1 Post by etniesbg » 31 Mar 2015 22:51

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Replace Double Quota batch file

#2 Post by foxidrive » 01 Apr 2015 02:05


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

Re: Replace Double Quota batch file

#3 Post by Squashman » 01 Apr 2015 05:55

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Replace Double Quota batch file

#4 Post by foxidrive » 01 Apr 2015 17:01

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"

Post Reply