2

I want to replace <Context useHttpOnly="false"> with <Context>

for /f "tokens=* delims=" %%A in ( %INTEXTFILE%) do (
SET string=%%A
setlocal enabledelayedexpansion
SET modified=!string:^<Context useHttpOnly^="false"^>=^<Context!
echo !modified! >> %OUTTEXTFILE%
endlocal
)

Output: nothing change.

Problem found because of equal sign and double quotes.

cathulhu
  • 641
  • 1
  • 9
  • 20
  • Batch is awful for this kind of stuff in my opinion. You could use something like this: http://www.seabreezecomputers.com/htmlstripper/ to strip attributes. Just put in which tags you want to keep and which attributes and press submit. I guess this wont work if this is something you have to do man times. – Gray Jul 16 '13 at 13:43
  • 1
    Batch is a major hassle when working with string manipulation and special characters. It can be done, but not without limitations. Highly recommend you use some other script language such as JScript/VBScript or PowerShell if you want to perform string manipulation. See http://stackoverflow.com/a/8591185/891976 – David Ruhmann Jul 16 '13 at 14:33

2 Answers2

2
@echo off
SET "string=<Context useHttpOnly="false">"
setlocal EnableDelayedExpansion
echo String: !string!
for /F "tokens=1,2 delims==>" %%i in ("!string!") do (
   if "%%i" equ "<Context useHttpOnly" if "%%~j" equ "false" set "modified=<Context>"
)
echo Modified: !modified!
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • I have tried it but it is not working. I have written it in separate bat file and run but not success. Actually I have to replace this string in xml file.. So I have to find it in xml file and replace it... – user2587496 Jul 17 '13 at 09:03
0

Here is a helper batch file called repl.bat - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855

This command may work for you...

type file.txt|repl "<Context.*.false.>" "<Context>" >newfile.txt
foxidrive
  • 40,353
  • 10
  • 53
  • 68