Results 1 to 13 of 13

Thread: [BATCH] file scripting |for /f in do for in echo %%%%a (not working)

  1. #1
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Lightbulb [BATCH] file scripting |for /f in do for in echo %%%%a (not working)

    Code:
    @echo off
    setlocal enabledelayedexpansion
    
    for /f "tokens=1-20 delims=m" %%a in (mdeeekkkke54m45y54ym54y)do (
    for %%A in (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) do (
    
    echo %%%%A
     
    ))
    i want it to be equal to %%a %%b %%c and so on
    however it doesnt recognize that im specifying the first %%a variable
    it just sees the second %%A value and trims the % signs...

    much help appreciated...

  2. #2
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by wantonman View Post
    ...

    Variables in batch files aren't case sensitive afaik.. This means that %%a and %%A are the exact same variable and so.. the first one's data is overwritten by the second in the inner loop.

    Use another variable name..
    I am Ggzz..
    Hackintosher

  3. #3
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    thanks theres no definate answere i switches %%A to %%z i still get same results and to as my unknowingness this is something tricky...
    i read that you can use ascii A-Z and a-z and 0-9 for variables in for loops

    http://judago.webs.com/variablecatches.htm

    this is the best but it still doest say anything about a for variable used with another for variable...

  4. #4
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by wantonman View Post
    thanks theres no definate answere i switches %%A to %%z i still get same results and to as my unknowingness this is something tricky...
    i read that you can use ascii A-Z and a-z and 0-9 for variables in for loops

    http://judago.webs.com/variablecatches.htm

    this is the best but it still doest say anything about a for variable used with another for variable...

    It's confusing exactly what you want to do..


    Try this (which is now syntactically correct due to the extra quotes).. Without them, it looks for a file called "mdeeekkkke54m45y54ym54y"..

    Batch Code:
    @echo off
    setlocal enabledelayedexpansion

    for /f "tokens=1-20 delims=m" %%a in ("mdeeekkkke54m45y54ym54y") do (

        echo %%a
        echo %%b
        echo %%c

        for %%d in (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) do (

            echo %%%%%%d
     
        )

    )


    I ran it using:

    cmd.exe /c foo.bat

    and the results are:

    Code:
    deeekkkke54
    45y54y
    54y
    
    %%a
    %%b
    %%c
    %%d
    %%e
    %%f
    %%g
    %%h
    %%i
    %%j
    %%k
    %%l
    %%m
    %%n
    %%o
    %%p
    %%q
    %%r
    %%s
    %%t

    If that's not what you want, I'm lost..

    Do you want the equivalent of the following? Or is the above correct already?

    Java Code:
    for (char c : "mdeeekkkke54m45y54ym54y".split("m")) { //might not be syntactically correct but meh..
       
       for (char d : new char['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', ....]) {
            if (d == c)
                System.out.println(c);
       }  

    }


    // OR??.. which makes not very much sense but sure..??

    for (char c : "mdeeekkkke54m45y54ym54y".split("m")) { //might not be syntactically correct but meh..
       
       //C will get re-assigned to whatever value is in the array..
       for (c : new char['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', ....]) {
            System.out.println(c);
       }  

    }

    Describe what you need or even write it in any other language and we can probably help/translate or figure it out.
    Last edited by Brandon; 08-23-2014 at 04:28 AM.
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    Heres a more simplifyed version
    @echo off
    setlocal enabledelayedexpansion

    for /f "tokens=1-20 delims=m" %%a in ("mdeeekkkke54m45y54ym54y")do (
    echo %%a
    echo %%b
    echo %%c

    for %%z in (a,b,c) do (
    echo %%%%%%z
    ))
    HERE IS THE OUTPUT
    deeekkkke54
    45y54y
    54y
    %%a
    %%b
    %%c
    on the output im trying to get something like

    deeekkkke54
    45y54y
    54y
    %%a <--this should equal "deeekkkke54"
    %%b <--this should equal "45y54y"
    %%c <--this should equal "54y"

    but the variables dont actually show theres any value in it at all as you can see
    man...

  6. #6
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by wantonman View Post
    but the variables dont actually show theres any value in it at all as you can see
    man...

    That's because you're not de-referencing the variables at all.. You're interpreting each one in the for-loop as a brand new character.

    See below (I know it's not "bash/shell" code.. I just used that tag for the highlighting):

    bash Code:
    @echo off
    setlocal enabledelayedexpansion

    for /f "tokens=1-20 delims=m" %%a in ("mdeeekkkke54m45y54ym54y")do (
        echo %%a
        echo %%b
        echo %%c

        for %%z in (%%a, %%b, %%c) do (
            echo %%z
        )
    )

    The result would be exactly what you described.. I'm a bit curious as to why you need it to do this since you already know that %%a holds the first node and so on.. But hopefully the above is what you meant.
    Last edited by Brandon; 08-23-2014 at 05:31 AM.
    I am Ggzz..
    Hackintosher

  7. #7
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    your solution works great for what i am trying to acheive
    @echo off
    setlocal enabledelayedexpansion
    for /f "tokens=1-4 delims=x" %%a in ("xthi1xthisxthf3")do (
    for %%d in (%%a,%%b,%%c) do (
    set x0=%%d
    if "!x0:~0,1!"=="t" if "!x0:~1,1!"=="h" if "!x0:~2,1!"=="i" if "!x0:~3,1!"=="s" echo %%d
    ))
    i really do not have a reason for this anymore since your solution did get me what i was trying to do but
    for whatever way is it possible to merge for variables in this type of way...

    heres a conceptual idea

    @echo off
    setlocal enabledelayedexpansion
    set x0=x
    set x1=2
    set x2=this is the example
    echo !%x0%%x1%!
    nottice the merging of the variables
    echo !%x0%%x1%!
    just in that sense can this work with using a for loop as well?

    @echo off
    setlocal enabledelayedexpansion
    for /f "tokens=1-4 delims=x" %%a in ("xthi1xthisxthf3")do (
    for %%d in (a,b,c)do (
    echo %%!%%d!
    ))
    the idea is that %%!%%d! would actually mean %%a %%b %%c in the loop...
    of course you dont use the !! for a for loop variable but its to show what the idea shoud be to do
    ... when it all expands it does something but it seems as if this is not possible in this example...

  8. #8
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by wantonman View Post
    ... when it all expands it does something but it seems as if this is not possible in this example...

    Use recursion or jumping?

    bash Code:
    @echo off
    setlocal enabledelayedexpansion

    set str="mdeeekkkke54m45y54ym54y"
    call :start "%str%"
    goto :end


    :start
    setlocal
    set list=%1
    set list=%list:"=%

    for /f "
    tokens=1* delims=m" %%a in ("%list%") do (

        ::Do whatver you want with %%a here.. I'll echo it below..

        echo %%a

               
        call :start "
    %%b"

    )
    endlocal
    :end


    It will print:

    Code:
    deeekkkke54
    45y54y
    54y
    Last edited by Brandon; 08-23-2014 at 03:12 PM.
    I am Ggzz..
    Hackintosher

  9. #9
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    i havent tried recursion or jumping but nontheless the batch file is up and running but the /F loop doesnt read everyline in the text file like it is documented to do so.
    here is my code
    ive included an example text file attachment
    its supposed to go threw the entire text file but it stops not even half way...
    Code:
    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    FOR /F "TOKENS=1-26 DELIMS=/" %%A IN (HTMLCODE.TXT) DO (
    FOR %%? IN (%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i,%%j,%%k,%%l,%%m,%%n,%%o,%%p,%%q,%%r,%%s,%%t,%%u,%%v,%%w,%%x,%%y,%%z) DO (
    ECHO %%?
    )
    )
    PAUSE
    ive read somewhere that it seems that whenever the /F for loop reads a text file that has maximum length lines theres some things that dont work
    Attached Files Attached Files

  10. #10
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Quote Originally Posted by wantonman View Post
    i havent tried recursion or jumping but nontheless the batch file is up and running but the /F loop doesnt read everyline in the text file like it is documented to do so.
    here is my code
    ive included an example text file attachment
    its supposed to go threw the entire text file but it stops not even half way...
    Code:
    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    FOR /F "TOKENS=1-26 DELIMS=/" %%A IN (HTMLCODE.TXT) DO (
    FOR %%? IN (%%a,%%b,%%c,%%d,%%e,%%f,%%g,%%h,%%i,%%j,%%k,%%l,%%m,%%n,%%o,%%p,%%q,%%r,%%s,%%t,%%u,%%v,%%w,%%x,%%y,%%z) DO (
    ECHO %%?
    )
    )
    PAUSE
    ive read somewhere that it seems that whenever the /F for loop reads a text file that has maximum length lines theres some things that dont work
    What about using Powershell?

    -Home

  11. #11
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    YEAH powershell id still not know
    here are some BATCH examples
    Code:
    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    FOR /F "TOKENS=1 DELIMS=" %%? IN ('DEBUG.EXE TEXT ^< DEBUG') DO (
    SET X0=%%?
    SET X0=!X0:~-16!
    FOR /L %%! IN (0,1,15) DO (
    IF !X1!==5 ECHO GOLD
    IF !X1!==5 ( IF !X0!==/ ( SET X1=6 ) ELSE ( SET X1=0 ) )
    IF !X1!==4 ( IF !X0!==d ( SET X1=5 ) ELSE ( SET X1=0 ) )
    IF !X1!==3 ( IF !X0!==r ( SET X1=4 ) ELSE ( SET X1=0 ) )
    IF !X1!==2 ( IF !X0!==a ( SET X1=3 ) ELSE ( SET X1=0 ) )
    IF !X1!==1 ( IF !X0!==c ( SET X1=2 ) ELSE ( SET X1=0 ) )
    IF !X1!==0 ( IF !X0!==/ ( SET X1=1 ) ELSE ( SET X1=0 ) ) ) )
    THIS one just fails ans does not find it

    Code:
    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    FOR /F "TOKENS=1 DELIMS=" %%? IN ('DEBUG.EXE TEXT ^< DEBUG') DO (
    SET X0=%%?
    SET X0=!X0:~-16!
    FOR /L %%! IN (0,1,15) DO (
    FOR %%@ IN ( / c a r d / ) DO (
    IF "!X0:~%%!,1!" == "%%@" ( SET X1=!X1!%%@ ) 
    ECHO !X1! | FIND "/card/" && SET X1= && ECHO GOLD ) ) )
    THIS one just fails even more

  12. #12
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Not sure what you are after, but heres how you can split in PowerShell
    Code:
    $Delim = '/'
    
    $File = Get-Content C:\Users\Home\htmlcode.txt
    
    $StringArr = $File -split $Delim
    
    $StringArr
    ~Home

  13. #13
    Join Date
    Sep 2010
    Location
    Azeroth
    Posts
    395
    Mentioned
    0 Post(s)
    Quoted
    17 Post(s)

    Default

    OKAY I GOT IT
    Code:
    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    SET X1=0
    FOR /F "TOKENS=1 DELIMS=" %%? IN ('DEBUG.EXE TEXT ^< DEBUG') DO (
    SET X0=%%?
    SET X0=!X0:~-16!
    FOR /L %%! IN (0,1,15) DO (
    IF !X1!==6 SET X2=!X2!!X0:~%%!,1!&IF "!X0:~%%!,1!"=="/" ECHO !X2!&SET X1=0&SET X2=
    IF !X1!==5 IF "!X0:~%%!,1!"=="/" (SET X1=6)ELSE (SET X1=0)
    IF !X1!==4 IF "!X0:~%%!,1!"=="d" (SET X1=5)ELSE (SET X1=0)
    IF !X1!==3 IF "!X0:~%%!,1!"=="r" (SET X1=4)ELSE (SET X1=0)
    IF !X1!==2 IF "!X0:~%%!,1!"=="a" (SET X1=3)ELSE (SET X1=0)
    IF !X1!==1 IF "!X0:~%%!,1!"=="c" (SET X1=2)ELSE (SET X1=0)
    IF !X1!==0 IF "!X0:~%%!,1!"=="/" (SET X1=1)ELSE (SET X1=0)
    ) )
    and can redirect to textfile with the >> as well
    the DEBUG file looks as so
    Code:
    D 0100 L A4A3
    Q
    
    -
    hex dump as necissary for the BATCH line limit i think 1000 characters
    the debug.exe dumps the hex and aside the contents in a 16 byte fashion
    so im able to capture each line in the FOR loop and the debug.exe program
    is scriptable so that makes it well for redirection and output in BATCH

    the TEXT file in the debug.exe command in the FOR loop is just a plain file html file

    this is working and will work for any asynchroneous files you may need sorting
    just swich around the key search terms and variables as needed as long as you have the
    debug.exe program unless your file isnt exeeding the line feed then you can just replace
    the hex dump with the actual file and swich the substrings

    was stumped in previous example but its working

    will print anything after the found phrase and untill the character specifyed

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •