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
Assigning a variable based on text search of a file
Moderator: DosItHelp
Re: Assigning a variable based on text search of a file
Most likely you would need a utility to prepare the pdf content for command line processing. Have a look at PDFtk. In order to help you we would need the original pdf file.
Steffen
Steffen
Re: Assigning a variable based on text search of a file
Steffen, Thank you for the quick response. I am attaching one of the PDF files as an example. I need to extract the work order number (10168536) from the PDF and store it as a variable to create a directory by the same name.
Re: Assigning a variable based on text search of a file
Edited post to remove file content.
Last edited by tlwalker3 on 28 Mar 2017 21:03, edited 1 time in total.
Re: Assigning a variable based on text search of a file
The site supports ZIP files.
You may have noticed that 12 0 0 12 108 524.5 Tm and the number you are looking for are not in the same line in your pasted content. No idea what the forum software did here. Please upload the file packed in a zip archive.
Steffen
You may have noticed that 12 0 0 12 108 524.5 Tm and the number you are looking for are not in the same line in your pasted content. No idea what the forum software did here. Please upload the file packed in a zip archive.
Steffen
-
- Posts: 16
- Joined: 25 Feb 2017 12:55
- Location: Russia
Re: Assigning a variable based on text search of a file
Code: Select all
textw "Setup Verification.pdf" > tmp.txt
for /f "tokens=integer delims=delimiter" %%a in ('type tmp.txt') do ....
....
textw.exe(win32 version 16Kb) here: http://adoxa.altervista.org/misc/index.html
See "Text v1.00 Display readable text within binary files"
Re: Assigning a variable based on text search of a file
What is the output of your current batch file? It looks like it should work to me.