09stephenb
09stephenb

Reputation: 9836

Reading different lines of a text file batch

If I have a text file call text.txt and I have this code to read it.

@ECHO OFF
SetLocal EnableDelayedExpansion

for /f "delims=" %%x in ('type text.txt') do ( 
    set "Var=%%x"
    ECHO !Var!
)
pause

How could I only display the third line of the text file. Thanks.

Upvotes: 1

Views: 73

Answers (1)

MC ND
MC ND

Reputation: 70951

@ECHO OFF
SetLocal DisableDelayedExpansion

for /f "usebackq skip=2 delims=" %%x in ("text.txt") do echo %%x & goto done
:done
pause

Skip two lines, write the third and exit the for loop

Upvotes: 1

Related Questions