1.

Solve : echo %%i throu FOR loop?

Answer»

Dear friends, in batch i write
Code: [Select]for /F "delims=" %%i in (MyFile.TXT) do echo.%%i>>NewFile.TXTif %%i contains for example "abc>def" (without the " ") it generates error because the > is interpreted as if i redirect abc to def
if i surround the expression with " " it's ok, but i can't do it because i must redirect to NewFile.TXT without the " "
Thanks for helpWhat OS are you using? It works fine here in Win 7.
I use Windows 7, Thank you very much, but sorry to say... i was too short, indeed my code is like this:
Code: [Select]for /f "delims=" %%i in (MyFile.TXT) do echo.%%i|find "ABC" >> NewFile.TXTand the line in the file contains 123>asd\678
and of course i get error: The system cannot find the PATH specified.
because >asd\ is interpreted as redirecting to a path that of course does not exist.
Thanks, any idea?Try this:

Quote

for /f "delims=" %%i in ('find "ABC" ^<MyFile.TXT') do echo.%%i>> NewFile.TXT


Or this:

Quote
find "ABC" <MyFile.TXT >>NewFile.TXT
Thank you very very much, i use the 1st suggetion because i need more manipulations.
Please tell me what is this use/behaviour of ^ before the input <
after your solution i tried instead of the use of ^ this: '"find "ABC"
OK i realized that it's an escape char that causes to interpret codes as simple chars.
I see that robvanderwoude has a lot about it.

again thank you very muchQuote from: yossi_moses on JULY 25, 2012, 08:38:35 AM
after your solution i tried instead of the use of ^ this: '"find "ABC" <MyFile.TXT"' and it also worked.

If you try that again in a for in do loop command you will find that it generates an error and will fail.

I'm glad you found the solution useful. Am I missing something?

Code: [Select]C:\>type myfile.txt
abc&def
abc<def
abc|def
abc>def
123>asd\678
123<asd\678
123&asd\678
123|asd\678

C:\>type test1.bat
@echo off
for /f "delims=" %%i in (myfile.txt) do echo.%%i>>newfile.txt

C:\>test1.bat

C:\>type newfile.txt
abc&def
abc<def
abc|def
abc>def
123>asd\678
123<asd\678
123&asd\678
123|asd\678

C:\>
A later post revealed that this was more like the real request:

for /f "delims=" %%i in (MyFile.TXT) do echo.%%i|find "ABC" >> NewFile.TXTDear Salmon Trout, 1st, thanks a lot. But it seems that indeed some thing is missed.
very strange, but
ECHO%%Var>FileName
is well escaped (no need for escape chars),
and
ECHO%%Var|FIND
is not escaped.

Please HELP me to UNDERSTAND how to thank in a way that my thank to any body will be counted in the forum.
Thanks


Discussion

No Comment Found