Return a Specific Line in a Text File

This is how you set a string to a specific line in a text file.

For example, the contents of your sample.txt text file:

This
Is
A
Test

You want to return “Is”

Script

setlocal enabledelayedexpansion
set count=1
for /f “delims=” %%a in (sample.txt) do (
if !count!==2 set strRet=%%a
set /a count+=1
)

echo %strRet%
Pause

email me