Я просто пробую простой цикл в процессе изучения пакетного скриптинга.
for /f "tokens=* delims= " %%a in (abc.txt) do echo %%a
Мой abc.text содержит
word1 word2 word3
Теперь вывод должен быть таким
word1
word2
word3
Но я просто получаю одну строку, а не три. Почему? Что я здесь не так делаю?
0
srikanth peetha
24 Апр 2017 в 22:02
2 ответа
Есть много способов сделать это:
@Echo off
Echo Variant 1
for /f "tokens=1-3" %%a in (abc.txt) do echo %%a & echo %%b & echo %%c
Echo Variant 2
For /f "tokens=*" %%a in (abc.txt) do for %%B in (%%a) Do Echo %%B
Echo Variant 3
For /f "tokens=*" %%a in ('type abc.txt') do for %%B in (%%a) Do Echo %%B
Пример вывода:
Variant 1
word1
word2
word3
Variant 2
word1
word2
word3
Variant 3
word1
word2
word3
3
user6811411user6811411
24 Апр 2017 в 20:18
Попробуйте одну из этих версий:
Версия 1 (помещает слово в файл, затем показывает затем на экране, также, что делает эхо):
@echo off
title text file reader/writer
echo This version inputs text that is predefined in the source code into a .txt file.
echo oh hey! I am text line 1>testwords.txt
echo oh hey! I am text line 2>>testwords.txt
echo oh hey! I am text line 3>>testwords.txt
echo oh hey! I am text line 4>>testwords.txt
echo Text entered! displaying below!
type testwords.txt
pause
del testwords.txt
exit
Версия 2:
@echo off
title text file reader/writer
echo This version displays predefined text in the source code as an "echo"
echo oh hey! I am text!
pause
exit
Версия 3:
@echo off
title text Displayer
echo This version displays User Entered text as an "echo" via the "set" command.
set /p text=Enter text here:
echo You have entered: %text%
pause
exit
Версия 4:
@echo off
title text saver/displayer
echo This version saves User Entered text as an "echo" via the "set" command, the "echo" command, and the "type" command.
set /p text=Enter text here:
echo You have entered: %text%>enteredtext.yourtextfile
type enteredtext.yourtextfile
pause
del enteredtext.yourtextfile
exit
-2
Kemstrike Gaming
24 Апр 2017 в 21:24
Новые вопросы
batch-file
Пакетный файл - это текстовый файл, содержащий серию команд, которые выполняются интерпретатором команд в системах MS-DOS, IBM OS / 2 или Microsoft Windows.