Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: echo %%i throu FOR loop  (Read 4225 times)

0 Members and 1 Guest are viewing this topic.

yossi_moses

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Unknown
    echo %%i throu FOR loop
    « on: July 25, 2012, 06:52:04 AM »
    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 help

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: echo %%i throu FOR loop
    « Reply #1 on: July 25, 2012, 07:08:09 AM »
    What OS are you using?  It works fine here in Win 7.

    yossi_moses

      Topic Starter


      Greenhorn

      • Experience: Beginner
      • OS: Unknown
      Re: echo %%i throu FOR loop
      « Reply #2 on: July 25, 2012, 07:44:30 AM »
      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?

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: echo %%i throu FOR loop
      « Reply #3 on: July 25, 2012, 08:05:26 AM »
      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

      yossi_moses

        Topic Starter


        Greenhorn

        • Experience: Beginner
        • OS: Unknown
        Re: echo %%i throu FOR loop
        « Reply #4 on: July 25, 2012, 08:38:35 AM »
        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" <MyFile.TXT"' and it also worked.

        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 much

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: echo %%i throu FOR loop
        « Reply #5 on: July 25, 2012, 09:24:27 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. :)

        Salmon Trout

        • Guest
        Re: echo %%i throu FOR loop
        « Reply #6 on: July 25, 2012, 11:44:25 AM »
        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:\>


        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: echo %%i throu FOR loop
        « Reply #7 on: July 25, 2012, 12:14:23 PM »
        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.TXT

        yossi_moses

          Topic Starter


          Greenhorn

          • Experience: Beginner
          • OS: Unknown
          Re: echo %%i throu FOR loop
          « Reply #8 on: July 26, 2012, 08:47:32 AM »
          Dear 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