0

Please, explain if is it way to move some row from text file on this way I want to get every row as some piece of string variable. I want do with this "variable row" what i want, so i need take this row and delete it from tf.txt, after what the second row will be tehnicaly the first row of tf.txt and i can use it as first row again.

@echo off

echo abc>tf.txt
echo d>>tf.txt
echo e>>tf.txt

rem only sets(and echoes) 1-st row; i want take 1st,2nd,3rd...
rem for example, first echo number of variable
rem then below, in new line, echo char(acters)

setlocal enabledelayedexpansion

for /l %%a in (1,1,5) do (
    set /a count=%%a 
    echo !count!
    set /p count=<tf.txt
    echo !count!
    rem on this point i need to delete 1-st row of tf.txt
    rem so i think it will echo the second row if first row
    rem doesnt exist at all
    pause
)

I made something that works. Please comment. Do you like this?

@echo off
rem line taker from txt files
md linetaker
cd linetaker
echo 000000000000000000000000000000000>group.txt
echo 111111111111111111111111111111111>>group.txt
echo 222222222222222222222222222222222>>group.txt
for /f %%x in (group.txt) do (
for /f %%l in ("%%x") do ( echo %%l>>tmp.txt)
move /y tmp.txt "%%x".txt
)
Zvonimir
  • 29
  • 6

1 Answers1

2

It is actually quite simple.

setlocal enabledelayedexpansion
set num=0
for /f %%i in (tf.txt) do (
   set /a num+=1
   set line[!num!]=%%i
)

echo line[1] = %line[1]%
echo line[2] = %line[2]%

Edited it to use the standard array notation according to Aacini's comment below.

user2033427
  • 853
  • 7
  • 8
  • I think i started to understand this batch programing. For now i only make deals with variables and strings. thanks to all who helping me!!!! – Zvonimir Apr 10 '13 at 14:58
  • I suggest you to use the standard array notation for these variables: `set line[!num!]=%%i` and `echo line[1] = %line[1]%`. Read these posts: http://stackoverflow.com/questions/10544646/dir-output-into-bat-array/10569981#10569981 and http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990 – Aacini Apr 10 '13 at 15:18