NoWar
NoWar

Reputation: 37633

How to get line from text file via findstr

How to get line from text file via findstr?

I expect to get this line for instance:

002-10.20.2.240 by input 002

I try this but it does not work...

@echo off
set /p line=""
set /p APP=numero de APP:

for /F "delims=" %%a in ('findstr /s /b "APP" Listin-7-4-2016.txt') do set line=%%a

echo. Linea del archivo detectada: %line%

pause

Example of Listin-7-4-2016.txt

002-10.20.2.240
003-10.20.3.240
004-10.20.4.240
006-10.20.2.241
007-10.20.7.240
008-10.20.7.241
016-10.20.6.240
017-10.20.6.241

Upvotes: 1

Views: 464

Answers (1)

Stephan
Stephan

Reputation: 56180

findstr /s /b "APP" ... searches for the string APP, but you want to search for the variable %APP%:

findstr /s /b "%APP%" ...

(by the way: you don't need /s if you search in a single file only)

Upvotes: 2

Related Questions