Getting and storing specific text from first line of text fi

February 12, 2020 at 21:03:34
Specs: Windows 10
Hi,

I am trying to select some specific text from text file, which has below text in it.

%%BoundingBox: 0 0 5 7
%%HiResBoundingBox: 0.324000 0.000000 4.338000 6.696000

What I am trying to capture is 0 0 5 7 from the first line ONLY and save it in a variable, which I will use in some other program. I have tried the following code in my Batch file it is actually capturing the 0.324000 0.000000 4.338000 6.696000 from the second line, when I need the first one.

FOR /F "tokens=1,2 delims=:" %%a IN (c:\test\CropBox.txt) DO (
IF /I "%%G" EQU "%%%%BoundingBox:" DO Set MyVar= %%G
echo %MyVar%

Any pointers will be highly appreciated.

Best,
P



See More: Getting and storing specific text from first line of text fi

Reply ↓  Report •

#1
February 12, 2020 at 21:15:19
Only gets the last qualifying line in file. If more than one, we'll reboot:
::--------------- begin script
@echo off & setlocal
for /f "tokens=1* delims=:" %%a in ('find "%%BoundingBox:"^<c:\test\CropBox.txt') do set myvar=%%b
echo Myvar: %myvar%
::------------- end script

message edited by nbrane


Reply ↓  Report •

#2
February 13, 2020 at 00:45:49
Thanks nbrane works perfect for me.

Reply ↓  Report •
Related Solutions


Ask Question