", I echo this word out and it doesn'...">

BATCH - Work with string (<,>) instead of redirecting

The last word in each text in the test.txt file is "</a>", I echo this word out and it doesn't seem to be a problem, but when I echo out in the for loop, cmd gave me this error: "The system is not can find the specified file. "
I know the problem is "<" and ">", this means redirecting that as an error is created. How am I going to make cmd, think I'm working with a string instead of a redirect?

 @echo off setlocal EnableDelayedExpansion set "remove_char=< /a>" echo !remove_char! for /f "skip=2 tokens=6*" %%a in (testing.txt) do ( set "string=%%a %%b" set string=!string:%remove_char%=! echo !string! ) pause >nul 
+6
source share
2 answers

If you want to use <and> characters as variables you must change to ^ or ^>

Otherwise, they will be treated as Input or Output!

+1
source

Perhaps you can replace this line

 set string=!string:%remove_char%=! 

with

 for %%i in (!remove_char!) do (set string=!string:%%i=!) 
0
source

All Articles