Assigning a variable based on text search of a file
Posted: 28 Mar 2017 13:13
I need to search a PDF file based on a string, then grab the value that follows and assign it to a variable name. If I open the PDF file in notepad, I can see the value and it is always preceded by the string "12 0 0 12 108 524.5 Tm(" .
So as an example: The PDF file contains "12 0 0 12 108 524.5 Tm(10168536)", I need to assign the value "10168536" as a dos variable so I can create a folder by the same name.
I am trying to use the FOR and/or FINDSTR commands to locate the value and assign the variable. Below is what I've tried so far and it is not working. Does anyone know if a better way to do this?
@echo off
setlocal enableextensions enabledelayedexpansion
set revision=
for /f "delims=" %%a in ("Setup Verification.pdf") do (
set line=%%a
if "x!line:~0,17!"=="
12 0 0 12 108 524.5 Tm
(" (
set revision=!line:~17!
)
)
echo !revision!
endlocal
So as an example: The PDF file contains "12 0 0 12 108 524.5 Tm(10168536)", I need to assign the value "10168536" as a dos variable so I can create a folder by the same name.
I am trying to use the FOR and/or FINDSTR commands to locate the value and assign the variable. Below is what I've tried so far and it is not working. Does anyone know if a better way to do this?
@echo off
setlocal enableextensions enabledelayedexpansion
set revision=
for /f "delims=" %%a in ("Setup Verification.pdf") do (
set line=%%a
if "x!line:~0,17!"=="
12 0 0 12 108 524.5 Tm
(" (
set revision=!line:~17!
)
)
echo !revision!
endlocal