Page 1 of 1

help me !!! i want create batch program read line by line ..

Posted: 25 Oct 2014 01:10
by sonyman
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 :roll:
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

Re: help me !!! i want create batch program read line by lin

Posted: 25 Oct 2014 01:29
by foxidrive

Code: Select all

@echo off
FOR /F "usebackq delims=" %%G IN ("text.txt") DO echo %%G
pause

Re: help me !!! i want create batch program read line by lin

Posted: 25 Oct 2014 03:52
by Compo
Drag and drop your .txt onto a .cmd file containing this:

Code: Select all

@(Findstr/n "^" %1&Pause)

Re: help me !!! i want create batch program read line by lin

Posted: 25 Oct 2014 04:13
by sonyman
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 !!!

Re: help me !!! i want create batch program read line by lin

Posted: 25 Oct 2014 06:47
by foxidrive
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.

Re: help me !!! i want create batch program read line by lin

Posted: 25 Oct 2014 10:50
by Squashman
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.

Re: help me !!! i want create batch program read line by lin

Posted: 27 Oct 2014 18:30
by rodrigolima
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