Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
sonyman
- Posts: 10
- Joined: 25 Oct 2014 01:01
#1
Post
by sonyman » 25 Oct 2014 01:10
i have file text (text.txt):
1
2
3
4
i want create batch program read line by line and display :
line1 : 1
line2 : 2
line3 : 3
line4 : 4
thank
i try but it not ok
Code: Select all
@echo off
pause
FOR /F "tokens=1,2,3,4" %%G IN (text.txt) DO (set a=%%G set b=%%H set c=%%I set d=%%J )
echo %a%
echo %b%
echo %c%
echo %d%
pause
-
Compo
- Posts: 600
- Joined: 21 Mar 2014 08:50
#3
Post
by Compo » 25 Oct 2014 03:52
Drag and drop your .txt onto a .cmd file containing this:
-
sonyman
- Posts: 10
- Joined: 25 Oct 2014 01:01
#4
Post
by sonyman » 25 Oct 2014 04:13
foxidrive wrote:Code: Select all
@echo off
FOR /F "usebackq delims=" %%G IN ("text.txt") DO echo %%G
pause
thank but really i want set line by line to input for other command
e.g
@echo off
echo u want read file 'pass.txt'?
pause
for /f "Delims=" %%a in (pass.txt) do (
set text=%%a)
echo.
echo text file reads :
%text%pause
hope u will understand !!!
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#5
Post
by foxidrive » 25 Oct 2014 06:47
sonyman wrote:thank but really i want set line by line to input for other command
hope u will understand !!!
If you describe the actual task to begin with then you will probably get a solution that works in the very next post.
You didn't get what you wanted because nobody knows what it is that you really want to do.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#6
Post
by Squashman » 25 Oct 2014 10:50
And please use code tags like everyone else is doing.
If you want to process each line then you need to do the processing inside your code block and use delayed expansion.
-
rodrigolima
- Posts: 21
- Joined: 19 Jul 2013 11:35
- Location: Brazil
#7
Post
by rodrigolima » 27 Oct 2014 18:30
Use this:
Code: Select all
@echo off
cls
setlocal enabledelayedexpansion
set linha=1
for /f "tokens=*" %%a in (text.txt) do (
echo line!linha!=%%a
set /a linha+=1
)
endlocal
pause
goto:eof