How can I echo nested variables inside a for loop?

schmiddl

Here is a for loop to save each line of a text file to its own variable:

@echo off 
setlocal enableextensions enableDelayedExpansion 

set count=0
for /f "tokens=*" %%a in (file.txt) do (
    set /a count=!count! + 1
    set var_!count!=%%a
)

endlocal

I would like to save the content of each variable to a separate new text file. How can I do this? I tried the following. But it does not work, because !var_!count!! is a variable inside a variable.

@echo off 
setlocal enableextensions enableDelayedExpansion 

set count=0
for /f "tokens=*" %%a in (file.txt) do (
    set /a count=!count! + 1
    set var_!count!=%%a
    echo !var_!count!!>file_!count!.txt
)

endlocal
MC ND
@echo off 
setlocal enableextensions enableDelayedExpansion 

set count=0
for /f "tokens=*" %%a in (file.txt) do (
    set /a "count+=1"
    set "var_!count!=%%a"
    for %%b in (!count!) do >file_!count!.txt echo !var_%%b!
)

endlocal

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How can I make a echo in echo in laravel with curly braces?

분류에서Dev

How can I print "-n" with `echo`?

분류에서Dev

How can I print specific integer variables in a nested dictionary by using Python?

분류에서Dev

How do I Successfully Echo a For Loop Into a Batch Script?

분류에서Dev

How can I add a delay inside each iteration of an _.each loop in underscore.js?

분류에서Dev

jQuery .dialog inside .each loop - new dialog content divs are written on each iteration - how can I destroy the old divs on each loop?

분류에서Dev

How can I join a nested Perl hash?

분류에서Dev

how can I do this with the variables in lua?

분류에서Dev

How can I break a symbolic link loop?

분류에서Dev

How can I iterate through a function with for loop?

분류에서Dev

How can I resolve this loop in c#?

분류에서Dev

How do I use a @Html.ActionLink inside a for loop

분류에서Dev

Perl: Creating new variables inside a loop

분류에서Dev

How can I pause a loop until I get a users input?

분류에서Dev

how can i loop for store items i want in ExtJS XTemplate?

분류에서Dev

How can I turn a delimited string into a nested hashtable in PowerShell?

분류에서Dev

Angular: how can i filter nested object properties?

분류에서Dev

How to handle nested template variables?

분류에서Dev

How can I save the output of "echo -e '\e]4;40;?\a'" into a variable, or pipe it?

분류에서Dev

How can i echo a variable posted from a textbox form using php?

분류에서Dev

How can I format this div without the text inside breaking a line?

분류에서Dev

How can I sort this object by 'sortby' key which inside an array?

분류에서Dev

How can I inspect if an element inside a cell is checked?

분류에서Dev

With regular expressions how can I get just the numbers inside brackets?

분류에서Dev

How can i check every alphabet inside one string variable?

분류에서Dev

How can I change the string object inside a string object?

분류에서Dev

JavaFX: How can I horizontally center an ImageView inside a ScrollPane?

분류에서Dev

How can I pass the parent to use in the JOptionPane that is inside a common method?

분류에서Dev

How can I call a bash function in bash script inside awk?

Related 관련 기사

  1. 1

    How can I make a echo in echo in laravel with curly braces?

  2. 2

    How can I print "-n" with `echo`?

  3. 3

    How can I print specific integer variables in a nested dictionary by using Python?

  4. 4

    How do I Successfully Echo a For Loop Into a Batch Script?

  5. 5

    How can I add a delay inside each iteration of an _.each loop in underscore.js?

  6. 6

    jQuery .dialog inside .each loop - new dialog content divs are written on each iteration - how can I destroy the old divs on each loop?

  7. 7

    How can I join a nested Perl hash?

  8. 8

    how can I do this with the variables in lua?

  9. 9

    How can I break a symbolic link loop?

  10. 10

    How can I iterate through a function with for loop?

  11. 11

    How can I resolve this loop in c#?

  12. 12

    How do I use a @Html.ActionLink inside a for loop

  13. 13

    Perl: Creating new variables inside a loop

  14. 14

    How can I pause a loop until I get a users input?

  15. 15

    how can i loop for store items i want in ExtJS XTemplate?

  16. 16

    How can I turn a delimited string into a nested hashtable in PowerShell?

  17. 17

    Angular: how can i filter nested object properties?

  18. 18

    How to handle nested template variables?

  19. 19

    How can I save the output of "echo -e '\e]4;40;?\a'" into a variable, or pipe it?

  20. 20

    How can i echo a variable posted from a textbox form using php?

  21. 21

    How can I format this div without the text inside breaking a line?

  22. 22

    How can I sort this object by 'sortby' key which inside an array?

  23. 23

    How can I inspect if an element inside a cell is checked?

  24. 24

    With regular expressions how can I get just the numbers inside brackets?

  25. 25

    How can i check every alphabet inside one string variable?

  26. 26

    How can I change the string object inside a string object?

  27. 27

    JavaFX: How can I horizontally center an ImageView inside a ScrollPane?

  28. 28

    How can I pass the parent to use in the JOptionPane that is inside a common method?

  29. 29

    How can I call a bash function in bash script inside awk?

뜨겁다태그

보관