Press "Enter" to skip to content

Batch File Example to Read Text File Line by Line

The following is an example of the Windows batch file to read a text file line by line.

Windows Batch File Example: Read Text File

The below batch program will read the text file (dummy.txt) from the current directory and will put the line into a variable, then will echo (print) the line on the screen.

Contents of the dummy.txt file.

This is the first line.
This is the second line.
This is the third line.
This is the forth line.
This is the fifth line.

readfile.bat

@echo off
for /f "tokens=*" %%s in (dummy.txt) do (
  echo %%s
)
pause

Test

To test create and put both the files into the same directory. Then run the file by typing its name at the Windows command prompt.

readfile.bat

Output

This is the first line.
This is the second line.
This is the third line.
This is the forth line.
This is the fifth line.
Press any key to continue . . .

See also:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. foxinfotech.in is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Comments are closed.