0

この方法でテキストファイルから行を移動する方法があるかどうかを説明してください。すべての行を文字列変数の一部として取得したいのです。この「変数行」でやりたいことをしたいので、この行を取得してtf.txtから削除する必要があります。2行目は技術的にtf.txtの最初の行になり、最初の行として使用できますまた。

@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
)

動作するものを作りました。コメントしてください。あなたはこれを好きですか?

@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
)
4

1 に答える 1

2

それは実際には非常に簡単です。

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]%

以下のAaciniのコメントに従って、標準の配列表記を使用するように編集しました。

于 2013-04-10T13:47:08.790 に答える