prudhvi krishna
prudhvi krishna

Reputation: 1

How to read file line by line using batch

Source file is present in below manner:-

abc

dfc

adbc

I am using below code to print the each line in the file.

for /f "tokens=* delims=" %%a in ('type input.txt') do (

set line=%%a
echo %line%
)

but the output is

adbc

adbc

adbc

What to do? Required output is:

abc

dfc

adbc

Upvotes: 0

Views: 9447

Answers (2)

Compo
Compo

Reputation: 38579

Unless you specifically need to manipulate the line or save the content of the last line in a variable there is absolutely no need to use a For loop:

Type input.txt

Upvotes: 1

itChi
itChi

Reputation: 662

@Squashman provided the answer really, but here it is written out:

setLocal EnableDelayedExpansion

for /f "tokens=* delims=" %%a in ('type input.txt') do (
set line=%%a

echo !line!
)

Upvotes: 0

Related Questions