Solved Replace-text-in-xml-using-batch-file and handle TAB

January 29, 2016 at 16:19:33
Specs: Windows 7
This is a follow up question to this post... five years later.

I was successful with this code as written except for a leading tab. Leading spaces are handled appropriately.

Presume the source file is:


The program as written will find and fix the first two instances but not the third and fourth.
The first is no spaces
The second is one space. I tested this successfully up to 10 spaces.
The third is one tab
The fourth is two tabs.

I would think that this line in the existing code would handle the tab but it did not work for me.
if defined test set test=!test: =!

Any assistance would be greatly appreciated.


See More: Replace-text-in-xml-using-batch-file and handle TAB

January 30, 2016 at 10:52:39
Hello: Judago's code worked for me using your test data. My guess is that you lost the TAB character somewhere in transferring the batch code. Use EDIT /70 to view the batchfile and make sure it has a tab and not a space at about line 10 which would be the third instance of "IF DEFINED TEST SET...".
PS: just to make sure we're on the same page, here's a Judago's code from Jan 21 2010:
@echo off
rem !'s are important
setlocal disabledelayedexpansion > new.xml
for /f "skip=2 delims=" %%a in ('find /n /v "" "%~1"') do (
set line=%%a
set test=%%a
setlocal enabledelayedexpansion
if defined test set test=!test:*]=!
if defined test set test=!test: =!
if defined test set test=!test: =!
if /i "!test:<currentVersion>3.0.0</currentVersion>=!"=="" (
echo matchhhhhh
set line=!line:*]=!
>> new.xml echo !line:3.0.0=!
) else (
rem delex var + substring + echo. don't like each other.
if "!test!"=="" (
>> new.xml echo.
) else (
>> new.xml echo !line:*]=!
if you cut/paste this code, the tab should come in the correct place in the code and the code should work since it did on mine.

message edited by nbrane

Report •

February 2, 2016 at 07:27:51

Thank you very much for your comment. I am still struggling.
I researched Edit /70 as I had not heard of that. Looks like it only available on 16 bit platforms. I am running Windows 7 64 bit version. I do not have XP available now.

Will notepad++ work?

I now see from my original post the leading spaces and tabs were removed from my data set. I presume you can see from your copy and pasted code that the leading tabs and spaces were removed. I presume the {tab} in the third line was removed from the copy and pasted code. I am going to use {} to indicate a non character key.

Just for clarity here is the data set I am using to test with.

Can you please tell me the exact key strokes for the third "if defined set test" entry?
I think the third line would be typed like this.
When I do this in notepad++ it looks like a single space and still does not work.

I tried this in notepad++
It looks like the original code but does not function.

Any help would be greatly appreciated.


Report •

February 2, 2016 at 19:03:37
✔ Best Answer
I think I'm "dusted" when it comes to 64-bit. Win-7 32-bit, which I used for my test, worked fine, so I think it's probably the 64-bit thing. You are correct in that the tab did not come through in the crossing from your post to my test-data. I don't know anything about notepad++ - I do have it (32-bit of course), but I've always used EDIT or DEBUG, both of which are verboten for 64-bit. Maybe there is a "run retro" option for 64 to allow 32-bit emulation. The other thing I always check for is if the data is Unicode, since batch mostly just works in ascii.
Your keystrokes analysis was "spot-on" - all spaces and tabs correct.
EXCEPT: you should only have one tab in this, from:
Another option is VBSCRIPT, but even that I don't trust to 64.
I will spare you my opinion of 64-bit, ha ha! But I know many users are forced to deal with it. I would advise anyone, at this stage, to try and keep a 32-bit system available for situations like this, if nothing else just to run tests and compare between the two.

message edited by nbrane

Report •

Related Solutions

February 3, 2016 at 03:03:14

Thank you for your reply. I have a Win XP laptop in the closet that I save for just an occasion. I will fire it up this weekend and look for the EDIT program and run it 70 columns wide. I presume it will work.

On 64 bit. I have a good friend that shares your contempt. His favorite program is File Manager all the way back from Win 3.1 days. He found a way to get it to work in Win7 32 but not 64. I think he may take the time to author it from scratch to work. lol.

Again, thank you.


Report •

Ask Question