batch file to parse a text file and pick out certain strings

i have a problem.
i actually have to write a batch file to generate a command to restore databases automatically.

one of the parameters in the command is giving a timestamp from the backup catalog file. backup catalog file is nothing but a text file which holds timestamps of when backups were taken.

now, the format of the catalog file is as follows:
begin dump=0
   datetime=12/25/2005 22:00:09
   completion_time=12/26/2005 00:09:13
end dump
begin dump=log_only
   datetime=12/26/2005 00:15:01
   completion_time=12/26/2005 00:15:17
end dump

This loops on and on. I need only the "datetime=...." entry for every "dump=0" section. maybe even where "backup_expired=Y" but backup_expired is not really important.

so what i need help with is....something to which i can give this catalog file as the input...and all the "datetime=...." lines will be printed of screen where "dump=0"

please let me know if im not explaining correctly.

thanks in advance.
much appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, Kunalap.

I think I figured out a solution.  I'm not sure this is the best way to do this, so if one of the other experts comes up with a better way, feel free to give them the points.  I think that you want to search a file (given as a parameter) for lines ending in "dump=0" and when found, print (to the screen) the first occurance of the line containing "datetime".  I am making the following assumptions:
 - This batch file will be run from a writable directory under Windows 2000/XP/2003
 - This batch file accepts 1 parameter which is the log file to parse
 - The "datetime" line will always be 3 lines down from the "dump=0" line
 - The length of the "datetime" line is constant (31 characters)

I think the following should work:

@echo off
set file=%1

if {%1}=={} echo Please specify filename&goto :EOF
if not exist %1 echo Can't find file %file%&goto :EOF

for /f %%a in ('findstr /i /n "dump=0$" %file%') do set dumpline=%%a&call :Process
goto :EOF

set /a start=2+%dumpline% 2>NUL
more /e  +%start% %file% > temptxt.txt
echo rcx >debugcmd.txt&echo 21 >>debugcmd.txt&echo w >>debugcmd.txt& echo q >>debugcmd.txt
debug temptxt.txt <debugcmd.txt >NUL
type temptxt.txt
del temptxt.txt
del debugcmd.txt

goto :EOF

Here's a different approach:

@echo off

if not exist "%~1" echo Please pass catalog file name to batch file.&goto :EOF

set inDump0=

for /f "tokens=1,2* delims== " %%a in ('type "%~1"') do call :PROCESS "%%a" "%%b" "%%c"

goto :EOF


if /i not "%~1"=="begin" goto CHECKINDUMP
if /i not "%~2"=="dump" goto :EOF

if "%~3"=="0" set inDump0=Y&goto :EOF

set inDump0=

goto :EOF


if not "%inDump0%"=="Y" goto :EOF
if /i not "%~1"=="datetime" goto :EOF

REM ** Do your processing here
echo Do processing using %~2 %~3

As with Gary's solution, the batch processing accepts a catalog name as input. You'll want to add your processing below the remark. The  %~2 holds the date and the %~3 holds the time.

Good Luck,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kunalap - I would use Steve's solution because it is cleaner than mine, has the capability for additional processing and has less dependancies than my solution (good job, Steve!)
Thanks Gary :)
kunalapAuthor Commented:
god bless u man.
damn u guys are good.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.