Home > other >  Search txt file for title and give value
Search txt file for title and give value

Time:07-28

I'm trying to read a txt file list from a folder, in this txt file is the report with some tags (name of the test) like the example:

t1.txt

Test1 400 Speed;P;188;GELE;0;N;11
Test2 300 Speed;P;200;GELE;0;N;11
Test3 200 Speed;P;201;GELE;0;N;11
Test4 100 Speed;P;188;GELE;0;N;11

The value i want to get is the 200 from test2 in this example, this value changes from txt file to another. The title name for the test is always the same, the line number can vary. How do i get a macro that just gives the value in this position

Test2 300 Speed;P;200;GELE;0;N;11

CodePudding user response:

That's quite easy: get the correct line with find or findstr and extract the desired token with a for /f loop:

@echo off
setlocal enabledelayedexpansion
for /f "tokens=3 delims=;" %%a in ('findstr /ibc:"test2 " t1.txt') do set "var=%%a"
echo the number is %var%
  • Related