Creating a filename from extraction

Micro-star international / Ms-7309
April 6, 2009 at 09:49:58
Specs: Microsoft Windows XP Professional, 2.31 GHz / 2047 MB
Hello all. I have a question that I hope someone can help me with. I have a batch script that looks at a PDF, converts it into text, searches for a set of variable keywords, and extracts the data into another txt file, which is fianlly converted back into a PDF.********script below******


move *.pdf c:\omniformat\watch

sleep 90

copy *.txt combined.txt

sleep 10

tfind "shipper" combined.txt > firstpass.txt

sleep 5

tfind "bol" combined.txt > secondpass.txt

sleep 5

tfind "railcar" combined.txt > thirdpass.txt

sleep 5

copy firstpass.txt+secondpass.txt+thirdpass.txt final.txt

sleep 20

c:\omniformat\omniformat.exe "c:\testing\mike\final.txt""pdf"

sleep 20

md c:\extracted_data

move c:\testing\mike\final.pdf C:\extracted_data

********************end of script*********

What I need-really need, is a way to make the file name of the final.txt file be part of the search string. For instance, I could really use the results for the "railcar" variable to be the filename. Example: the result for the "railcar" search brought back UTLX12345, which is what I need the filename to be, so I can put it in a searchable format. Thanks so much, and I hope I made sense.


See More: Creating a filename from extraction

Report •


#1
April 6, 2009 at 12:47:21
I wish I had a way to convert pdf to txt, or almost anything else. I've always hated pdfs and never managed to convert any. Even with Adobe pro. LOL


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
April 6, 2009 at 13:11:31
I use a program called omniformat. It converts quite a few files both ways. If you try it and like it, I have a file I will email you that will enhance its use. OK, forget I mentioned PDF. say I want to grab a line out of a txt file, and make that line my filename. Possible?

Report •

#3
April 6, 2009 at 14:04:36
If you have a file that contains:

one
this is line two
three goes here
=================
This will grab the whole 2nd line:

@echo off & setLocal EnableDelayedExpansion

set N=
for /f "tokens=* delims=" %%a in (my.txt) do (
set /a N+=1
if !N! equ 2 set FN=%%a
)
echo ren somefile !FN!

:: To get just the 2nd word of the 3rd line:

set N=
for /f "tokens=1-2 delims=" %%a in (my.txt) do (
set /a N+=1
if !N! equ 3 set FN=%%b
)
echo ren somefile !FN!

=========================
and so on


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions

#4
April 6, 2009 at 15:12:43
Thanks:) The script is almost perfect. With some editing, it ren the file in dos, but it does not give it an extension, and I do not know where to edit the file for that. Thanks in advance, Vellocet

*****************************
@echo off & setLocal EnableDelayedExpansion

set N=
for /f "tokens=* delims=" %%a in (final.txt) do (
set /a N+=1
if !N! equ 7 set FN=%%a
)
echo ren final.txt !FN!
***********************************************************
notice I went to the 7th line..very nice script, btw.


Report •

#5
April 6, 2009 at 15:49:20
If the ext will always be txt use the modified script below.

*****************************
@echo off & setLocal EnableDelayedExpansion

set N=
for /f "tokens=* delims=" %%a in (final.txt) do (
set /a N+=1
if !N! equ 7 set FN=%%a
)
echo ren final.txt !FN!.txt
*********************************************************


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#6
April 7, 2009 at 08:09:20
The process goes through without error in the command shell, but the file never gets renamed. If I manually rename it, it works.
*****last line of batch below*******

ren 1.txt DenaturedEthylAlcohol.txt


you can see that the syntax is correct. If I type that in manually, the name change takes place. Ideas? Thanks in advance for your patience.


Report •

#7
April 7, 2009 at 09:32:02
would it be possible to look for multiple words in a file and make those words the filename?


*********EXAMPLE .TXT FILE*****************

Shipper: Chevron
Railcar Number: utlx82373876

*****************************************************
That is what my data looks like(kind of) when converted from PDF. My Boss wants the shipper, railcar number, and datestamp to be the filename. The problem is the railcar number changes all the time, and it is on different lines sometimes.


Report •

#8
April 8, 2009 at 05:27:08
One thing at a time. As posted, the script previews what's to be done. To activate the rename edit out the ECHO which precedes ren.

Next, if you have a fil like this where the lines of interest are 4 and 5:

one
this is line two
three goes here
Shipper: Chevron
Railcar Number: utlx82373876


Try this:

=================
:: ren to shipper and railcar num

@echo off & setLocal EnableDelayedExpansion

set N=
for /f "tokens=* delims=" %%a in (my.txt) do (
set /a N+=1
if !N! equ 4 (call :sub1 %%a)
if !N! equ 5 (call :sub2 %%a)
)

echo ren somefile !ship!-!car!

goto :eof

:sub1
set ship=%2
goto :eof

:sub2
set car=%3
goto :eof


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question