Batch File Range - windows

Thanks in advanced for your help! I have a batch file question for you guys. So we keep up with one of our client's backups. They're located over 200 miles away from us. We bring their backups over via remote desktop. We've found that using the copy function via the command prompt is MUCH faster than any other method of copy/paste. The person who is in charge of bringing them over often forgets to do so. I've only just started using batches, but I created a small batch program that will ask the user which file to bring over so he doesn't have to "copy n:\backups\blah \tsclient\h\backups\blah" which can be quite error prone. The following is the batch file:
#echo off
title Copy Zipbacks
:loopagain
set /p date=Enter the date that needs to be copied over (yyyymmdd format):
copy h:\zipbackups\daily%date%.zipx \\tsclient\h\benton_off_site_backup\zipbackups
set /p again=Copy Another Daily Zip file? (Y/N):
IF "%again%"=="Y" GOTO loopAgain
IF "%again%"=="N" GOTO goAway
:goAway
exit
This is good if there are only a handful of backups to be brought over. My question is this; Is there a way to bring over a range of backups? The file is setup as follows:
dailyYYYYMMDD.zipx
i.e. daily20140917.zipx
I have no problem asking for the date range, but getting the .bat to loop through the folder and getting only those that meet the criteria is where I'm running into the issue. Any thoughts?

You may use a for to enumerate files:
#echo off
title Copy Zipbacks
:loopagain
set /p start_date=Enter start date that needs to be copied over (yyyymmdd format):
set /p end_date=Enter end date (yyyymmdd format) or nothing to match only start date:
if not defined end_date set end_date=%start_date%
for %%f in (h:\zipbackups\daily*.zipx) do if "%%~nf" geq "daily%start_date%" if "%%~nf" leq "daily%end_date%" copy %%f \\tsclient\h\benton_off_site_backup\zipbackups
set /p again=Copy Another Daily Zip file? (Y/N):
IF "%again%"=="Y" GOTO loopAgain
IF "%again%"=="N" GOTO goAway
:goAway
exit

I came across a trick with xcopy that lets you generate a sequence of valid dates. The following script will generate the sequence and then copy each of the files.
#echo off
::set /p date=Enter the start date that needs to be copied over (yyyymmdd format):
::set /p end=Enter the end date that needs to be copied over (yyyymmdd format):
set /a date=20010218
set /a end=20010302
set /a y=%date:~0,4%
set /a m=%date:~4,2%
set /a d=%date:~6,2%
echo INPUT = %y% %m% %d%
:getnextvaliddate
set /a d+=1
if %d% gtr 31 (
set d=1
set /a m+=1
if %m% gtr 12 (
set m=1
set /a y+=1
)
)
echo %y% %m% %d%
xcopy /d:%m%-%d%-%y% /h /l "%~f0" "%~f0\" >nul 2>&1 || goto getnextvaliddate
call :prettydate
if %y% equ %end:~0,4% (
if %m% equ %end:~4,2% (
if %d% equ %end:~6,2% (
goto :EOF
)
)
)
goto :getnextvaliddate
:prettydate
if %d% lss 10 (
set dd=0%d%
) else (
set dd=%d%
)
if %m% lss 10 (
set mm=0%m%
) else (
set mm=%m%
)
echo copy h:\zipbackups\daily%y%%mm%%dd%.zipx \\tsclient\h\benton_off_site_backup\zipbackups
goto :EOF
Output on my machine:
INPUT = 2001 2 26
2001 2 27
copy h:\zipbackups\daily20010227.zipx \\tsclient\h\benton_off_site_backup\zipbackups
2001 2 28
copy h:\zipbackups\daily20010228.zipx \\tsclient\h\benton_off_site_backup\zipbackups
2001 2 29
2001 2 30
2001 2 31
2001 3 1
copy h:\zipbackups\daily20010301.zipx \\tsclient\h\benton_off_site_backup\zipbackups
2001 3 2
copy h:\zipbackups\daily20010302.zipx \\tsclient\h\benton_off_site_backup\zipbackups

Related

Batch Programming (Nested loops) using labels, program does not work

I don't understand why this script doesn't seem to work and doesn't even pause to see where the error is.. Here is the code for the batch file:
I want this batch to output a series of birthdays starting from Ihf0101 till Ihf3112
set /a month=1
:m
if %month% leq 12
(
set /a day=1
:d
if %day% leq 31
(
if %day% leq 9 set birthday=Ihf0%day%
if %day% gtr 9 set birthday=Ihf%day%
if %month% leq 9
(
set birthday=%birthday%0%month%
echo %birthday%
)
if %month% gtr 9
(
set birthday=%birthday%%month%
echo %birthday%
)
set /a day+=1
goto :d
)
set /a month+=1
goto :m
)
pause
Use for /L loops instead:
#echo off
setlocal enabledelayedexpansion
set "y=2017"
for /l %%m in (101,1,112) do (
set "m=%%m"
for /l %%d in (101,1,131) do (
set "d=%%d"
xcopy /d:!m:~1!-!d:~1!-%y% /l . .. >nul 2>&1 && echo lhf!d:~1!!m:~1!
)
)
two little tricks:
- counting from 101 to 131 and taking the last two digits only gives you a two-digit format always (with leading zero for numbers below 10)
- using xcopy to check if the date is really existent (I learned that here) (necessary to know the year for proper calculation of leap-years)

get a number from txt add 1 and write it back in bat file

The titles says everything, I have a txt file called totalcred.txt with a number, all I want to do is:
keep the number written on the .txt file in a variable
add +195 to this variable
replace the old number with the newer (the one who got +195)
But nothing on this earth worked until now, I got dissapointed.
Here's my code so for (I tried lot of things too):
FOR /F "tokens=1" %%a IN (totalcred.txt) DO (
set val=%%a
IF [%val%] GEQ [0] (
set /a val += 195
echo %val% > totalcred.txt
)
)
You don't even need a for loop, which as you can imagine is problematic when trying to read from the same file you're writing to:
#Echo Off
Set/P "val="<totalcred.txt
If %val% GEq 30000 GoTo :EOF
Set/A "val+=195"
(Echo(%val%)>totalcred.txt
FOR /F "tokens=1 delims=" %%a IN (totalcred.txt) DO (
set /a val=%%a+0
goto con
)
:con
set /a val2=%val%+100
echo %val2%
(Echo(%val2%)>totalcred.txt

Windows Batch File not Validating Year

So I have a windows batch script that validates to see if the date format I entered is in the correct format. Everything is working fine with it except when it gets to the year part of it. It doesn't seem to validate the year in the correct format of xxxx. It will accept any number. Where is it breaking, I can't tell? Fix suggestions? Thank you!
set i=0
for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do (
set /A i+=1
set dpm[!i!]=%%a
)
set /P "inDate=Please insert FNOL date (MM-DD-YYYY format): "
if "%inDate:~2,1%%inDate:~5,1%" neq "--" goto invalidDate
for /F "tokens=1-3 delims=-" %%a in ("%inDate%") do set "MM=%%a" & set "DD=%%b" & set "YYYY=%%c"
ver > NUL
set /A month=1%MM%-100, day=1%DD%-100, year=1%YYYY%-10000, leap=year%%4
if errorlevel 1 goto invalidDate
if not defined dpm[%month%] goto invalidDate
if %leap% equ 0 set dpm[2]=29
if %day% gtr !dpm[%month%]! goto invalidDate
if %day% lss 1 goto invalidDate
SET fnoldate=%YYYY%-%MM%-%DD%
ECHO.
SET /P confirmdate=You entered a FNOL date of "%fnoldate%". Is this correct? [y/n]
ECHO.
You're missing some components of your batch file.
At the top, you should have the following:
#Echo Off
SetLocal EnableDelayedExpansion
Your code has some GoTo references, but it can't go anywhere. You should add the following at the bottom:
GoTo :EOF
:invalidDate
echo Invalid date.
Hmm. Giving an example of a failure would have been useful.
Let's take an 'invalid' year like 14.
Your calculation for 01-01-14 would be year=114-10000
You really need to check that year has length 4 first.
if "%year:~3%=="" goto invaliddate
if not "%year:~4%=="" goto invaliddate
and you are not then checking after year-is-numeric for year in a valid range
Here is a method to validate the year:
#echo off
set year=1980
for /f "delims=1234567890" %%a in ("%year%") do echo you must enter numeric characters only & goto :EOF
if %year% GEQ 1800 if %year% LEQ 2014 (
echo year is between 1800 and 2014
) else (
echo enter a year between 1800 and 2014
)

Batch Script: Validate Date Input

I have a batch file that I use to create new project folders for clients that walks a user through the creation process and adds the appropriate files and folders to a central location. I need to add an input section so they can put a date (not always current date) in and it is included in the naming of the files.
The issue I have, and I have hunted high and low and can't find my answer, is that I need to dummy proof the date input. I want the user to input the date in the MM-DD-YYYY format including dashes. It needs to then format it into YYYY-MM-DD. It needs to be smart enough that it forces the user to use the required format of MM-DD-YYYY; has to be numbers and dashes, no slashes, the right amount of characters, and so forth.
I haven't been able to find anything close to even remotely get me where I need to be so I am asking the awesome geniuses out there for help in this regard as it is driving me up a wall. Below is my script code. I need this input to go right after the job type is selected. "Please insert date (MM-DD-YYYY format): "
#echo off
setlocal EnableDelayedExpansion
set version=7.95
set projectpath="P:"
set workbookpath="\\server2\Documents\Blanks (DO NOT EDIT)\dryingworkbook_v3r75.xls"
set questions="\\server2\Documents\Blanks (DO NOT EDIT)\Abatement and Mold Questions.txt"
set notes="\\server2\Documents\Blanks (DO NOT EDIT)\Job Notes.docx"
set info="\\server2\Documents\Blanks (DO NOT EDIT)\Job Information.docx"
set bizname=1
ECHO =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ECHO = Welcome to SERVPRO Project Creation Wizard v%version% =
ECHO =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ECHO.
:sof
ECHO.
ECHO Is this new project for a Residential or Commercial job?
:loopJobType
SET /P jobtype=Enter [r] for Residential or [c] for Commercial:
ECHO.
IF "%jobtype%" == "r" GOTO :loopResidential
IF "%jobtype%" == "R" GOTO :loopResidential
IF "%jobtype%" == "c" GOTO :loopCommercial
IF "%jobtype%" == "C" GOTO :loopCommercial
GOTO :loopJobType
:loopResidential
ECHO You have chosen to create a new Residential job project.
ECHO.
set type=1
GOTO :loopFirstName
:loopCommercial
ECHO You have chosen to create a new Commercial job project.
ECHO.
set type=2
SET /p bizname=Please enter the business name:
ECHO.
IF "%bizname%"=="" GOTO :loopCommercial
:loopFirstName
SET /P FirstName=Please enter the insured's first name:
IF "%FirstName%"=="" GOTO :loopFirstName
call :format FirstName
:loopLastName
ECHO.
SET /P LastName= Please enter the insured's last name:
IF "%LastName%"=="" GOTO :loopLastName
call :format LastName
SET FullName=%LastName%, %FirstName%
SET FullBizName=%bizname% (%FullName%)
goto :ConfirmProject
:format
set Name=!%1!
set Head=%Name:~0,1%
set Tail=%Name:~1%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set Head=!Head:%%a=%%a!
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do set Tail=!Tail:%%a=%%a!
set %1=%Head%%Tail%
GOTO :eof
:ConfirmProject
ECHO.
IF "%type%" == "1" SET /P yesno=Are you sure you want to add "%FullName%" to the Project directory? [y/n]
IF "%type%" == "2" SET /P yesno=Are you sure you want to add "%FullBizName%" to the Project directory? [y/n]
IF "%yesno%" == "y" GOTO :CreateProject
IF "%yesno%" == "Y" GOTO :CreateProject
IF "%yesno%" == "n" GOTO :sof
IF "%yesno%" == "N" GOTO :sof
GOTO :ConfirmProject
:CreateProject
IF "%type%" == "1" SET ProjectName=%FullName%
IF "%type%" == "2" SET ProjectName=%FullBizName%
:: Create a folder containing a new project.
mkdir "%projectpath%\%ProjectName%"
ECHO.
ECHO.
ECHO Creating a Project directory for "%ProjectName%" ...
:: Create a folder within said project that will contain job documents.
ECHO Creating a Documents directory for "%ProjectName%" ...
mkdir "%projectpath%\%ProjectName%\Documents"
:: (Taken out of use 7-15-13) ECHO Adding a Job Information file for "%ProjectName%" ...
:: (Taken out of use 7-15-13) copy /-Y %info% "%projectpath%\%ProjectName%\Documents\Job Information - %ProjectName%.docx"
ECHO Documents directory creation for "%ProjectName%" finished ...
:: Create a folder within said project that will contain drying workbook(s).
ECHO Creating a Drying Workbook directory for "%ProjectName%" ...
mkdir "%projectpath%\%ProjectName%\Drying Workbooks"
:: Copy a new blank workbook to the project workbook directory and give it the proper name.
ECHO Adding a Drying Workbook for "%ProjectName%" ...
copy /-Y %workbookpath% "%projectpath%\%ProjectName%\Drying Workbooks\DRY 1_%ProjectName%.xls"
ECHO Adding an Abatement and Mold Questions file for "%ProjectName%" ...
copy /-Y %questions% "%projectpath%\%ProjectName%\Drying Workbooks\Abatement and Mold Questions.txt"
ECHO Drying Workbook directory creation for "%ProjectName%" finished ...
:: Create a folder within said project that will contain original photos.
ECHO Creating a Photos directory for "%ProjectName%" ...
mkdir "%projectpath%\%ProjectName%\"Photos
:: Create a folder within said project photo folder that will contain resized photos.
mkdir "%projectpath%\%ProjectName%\Photos\Resized"
mkdir "%projectpath%\%ProjectName%\Photos\Upload"
ECHO Photos directory creation for "%ProjectName%" finished ...
:: Add in Job Notes file.
ECHO Adding a Job Notes files for "%ProjectName%" ...
copy /-Y %notes% "%projectpath%\%ProjectName%\Job Notes - %ProjectName%.docx"
:: Log the creation of the project.
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CDATE=%%B
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
echo off > "%projectpath%\Logs\%ProjectName% - [Project Created %date% by %computername%].txt"
ECHO Logging "%ProjectName%" creation date and time...
ECHO Project directory creation for "%ProjectName%" finished ...
GOTO :OpenProject
:OpenProject
:: Ask if the project should be opened now. If so open and close script, else close script.
set /p reply=Do you want to open the "%ProjectName%" project now? [y/n]
if "%reply%" == "y" %SystemRoot%\explorer.exe "%projectpath%\%ProjectName%"
IF "%yesno%" == "Y" %SystemRoot%\explorer.exe "%projectpath%\%ProjectName%"
GOTO :eof
IF "%yesno%" == "n" GOTO :No
IF "%yesno%" == "N" GOTO :No
exit
:No
ECHO.
ECHO.
ECHO You have successfully created a new project for %ProjectName%.
ECHO.
ECHO Press any key to exit . . .
PAUSE>NUL
:eof
The Batch file below check that the inserted date have the right format and that it represent a valid date, that is, that have the right number of days in each month, even for February on leap years!
#echo off
setlocal EnableDelayedExpansion
set i=0
for %%a in (31 28 31 30 31 30 31 31 30 31 30 31) do (
set /A i+=1
set dpm[!i!]=%%a
)
set /P "inDate=Please insert date (MM-DD-YYYY format): "
if "%inDate:~2,1%%inDate:~5,1%" neq "--" goto invalidDate
for /F "tokens=1-3 delims=-" %%a in ("%inDate%") do set "MM=%%a" & set "DD=%%b" & set "YYYY=%%c"
ver > NUL
set /A month=1%MM%-100, day=1%DD%-100, year=1%YYYY%-10000, leap=year%%4 2>NUL
if errorlevel 1 goto invalidDate
if not defined dpm[%month%] goto invalidDate
if %leap% equ 0 set dpm[2]=29
if %day% gtr !dpm[%month%]! goto invalidDate
if %day% lss 1 goto invalidDate
echo Date correct: %YYYY%-%MM%-%DD%
goto :EOF
:invalidDate
echo Bad date
You can check whether your string is valid easily with the findstr command.
set /p date= Please insert date (MM-DD-YYYY format):
echo %date%| findstr /r "^[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]$">nul
if errorlevel 1 (
echo invalid date
)
pause
(^ means beginning of line, while $ stands for end of line.)
Now for the reformatting MM-DD-YYYY into YYYY-MM-DD, you can split your string and than reassemble it. Since it's a fixed format, this isn't too hard either:
set yyyy=%date:~6,4%
set mm=%date:~0,2%
set dd=%date:~3,2%
set newDate=%yyyy%-%mm%-%dd%
echo %newDate%
The first number in each command resembles the position where the string will be cut.
The second number resembles the length of the substring.
I made a function :getdate who test the date try it;
It will test if the separators are correct, the value range for thr month and the day and
if the values are NUM.
#ECHO OFF
setlocal enabledelayedexpansion
:GetDate
set /p $D=Enter a date (MM-DD-YYYY) :
set $separate=%$d:~2,1% %$d:~5,1%
for %%a in (%$separate%) do (if "%%a" neq "-" (echo Wrong Separator : %%a
pause
goto:Getdate))
set $D=%$D:-= %
set $c=1
for %%a in (%$d%) do (call:test !$c! %%a
set /a $c+=1)
if !$c!==4 set $DateOK=%$month%-%$day%-%$Year%
echo This DATE IS OK %$dateOK%
exit /b
:test
if %1 equ 1 (echo %2 | findstr [0-9][0-9]
if errorlevel 1 (echo Unvalid value for Month [NOT NUM]: %2
pause
goto:getdate)
if %2 GTR 12 (echo Unvalid value for Month [VALUR RANGE +]: %2
pause
goto:getdate)
if %2 LSS 1 (echo Unvalid value for Month [VALUR RANGE -]: %2
pause
goto:getdate)
set $month=%2)
if %1==2 (echo %2 | findstr [0-9][0-9]
if errorlevel 1 (echo Unvalid value for Day [NOT NUM]: %2
pause
goto:getdate)
if %2 GTR 31 (echo Unvalid value for Day [VALUR RANGE +] : %2
pause
goto:getdate)
if %2 LSS 01 (echo Unvalid value for Day [VALUE RANGE -]: %2
pause
goto:getdate)
set $day=%2)
if %1==3 (echo %2 | findstr [0-9][0-9][0-9][0-9]
if errorlevel 1 (echo Unvalid value for Year [NOT NUM] : %2
pause
goto:getdate)
set $Year=%2)
#ECHO OFF
SETLOCAL enabledelayedexpansion
CALL :getverdate
ECHO DATE %indate% is OK.
GOTO :EOF
::
:: Get and verify date in format mm-dd-yyyy; reformat as yyyy-mmm-dd
::
:regetdate
ECHO "%indate%" is not in format "MM-DD-YYYY" or is invalid
:getverdate
SET /p indate="Please insert date (MM-DD-YYYY format): "
IF NOT "%indate:~2,1%%indate:~5,1%"=="--" GOTO regetdate
SET checkdate=9%indate:-=%
IF NOT "%checkdate:~8%"=="%checkdate:~8,1%" GOTO regetdate
FOR %%a IN (0 1 2 3 4 5 6 7 8 9) DO SET checkdate=!checkdate:%%a=!
IF DEFINED checkdate GOTO regetdate
IF %indate:~3,2%==00 GOTO regetdate
FOR %%i IN (01:31 02:29 03:31 04:30 05:31 06:30 07:31 08:31 09:30 10:31 11:30 12:31) DO (
FOR /f "tokens=1,2delims=:" %%j IN ("%%i") DO IF %%j==%indate:~0,2% if "%%k" geq "%indate:~3,2%" GOTO goodday
)
GOTO regetdate
:goodday
IF "%indate:~-4%" geq "1980" IF "%indate:~-4%" leq "2099" GOTO goodyear
GOTO regetdate
:goodyear
SET /a checkdate=%indate:~-4% %% 4
IF "%indate:~0,2%%indate:~3,2%"=="0229" IF %checkdate% neq 0 GOTO regetdate
SET indate=%indate:~-4%-%indate:~0,2%-%indate:~3,2%
GOTO :eof
Here's another 'get and validate date` routine.
Note that in your code you should never set a variable called date. %date% will return the current date - it's a "magic variable" controlled by CMD. Other such variables include %time%, %random% and %errorlevel%. Setting any of these overrides the system-established value.
You could present the user with three prompts - year, month, day.
set /p y="Please enter year (YYYY): "
set /p m="Please enter month (MM): "
set /p d="Please enter day (DD): "
set date=%y%-%m%-%d%
If you would like to verify the length of the input something like:
if [%y:~4%] NEQ [] echo year entered incorrectly & goto :getDate
You can assume if %y% is greater than four characters - i.e. if %y:~4% is not null - that it has been entered incorrectly (see Dos Tips on string manipulation). The same principal applies for day and month, except they should be two characters.
Obviously for that example you would need to add the label :getDate before the user input.
You may use ReadFormattedLine subroutine for all kind of formatted input. For example, the command below read 3 numbers in a date format; the routine just accept digits, insert the hyphens and continue automatically after read the last digit. If the user delete characters, the hyphens are also deleted automatically.
call :ReadFormattedLine myDate="##-##-####" /M "Please insert date (MM-DD-YYYY format): "
This subroutine is written in pure Batch so it does not require any additional program, and it allows several formatted input operations, like read passwords, convert letters to uppercase, etc. You may download ReadFormattedLine subroutine from Read a line with specific format.

Need to search a file based on timestamps within the lines of the file using Windows XP/7 batch

I have a file that contains time-stamped lines of text. I need to search for lines that start at a specific time and end at a specific time. I already have the times needed stored in variables. I need to be able to break up the line and the time into tokens, i believe, and search for tokens that are geq "start time" and leq "stop time". I know this requires a FOR loop, but I'm not sure how to break this up. (Also , I have found that 8 and 9 fail when used for inputs. I am working on this, I think by hr_start+100 and hr_stop+100 before compare and -100 after compare, etc.) Any improvements on this are appreciated. My goal is a completely error-free interface.
:time_begin
cls
echo.
echo (Use 24-hour clock)
echo.
:hr_start
set /a hr_start=0
set /p hr_start=What hour to start?
if "%hr_start%"=="b" goto day
if %hr_start% geq 0 (
if %hr_start% leq 23 (
if %hr_start% lss 10 set hr_start=0%hr_start%) else (
echo Invalid hour
goto hr_start))
:min_start
set /a min_start=0
set /p min_start=What minute to start?
if "%min_start%"=="b" goto hr_start
if %min_start% geq 0 (
if %min_start% leq 59 (
if %min_start% lss 10 set min_start=0%min_start%) else (
echo Invalid minute
goto min_start))
:sec_start
set /a sec_start=0
set /p sec_start=What second to start?
if "%sec_start%"=="b" goto min_start
if %sec_start% geq 0 (
if %sec_start% leq 59 (
if %sec_start% lss 10 set sec_start=0%sec_start%) else (
echo Invalid second
goto sec_start))
echo.
echo.
:hr_stop
set /a hr_stop=23
set /p hr_stop=What hour to stop?
if "%hr_stop%"=="b" goto sec_start
if %hr_stop% geq 0 (
if %hr_stop% leq 23 (
if %hr_stop% lss 10 set hr_stop=0%hr_stop%) else (
echo Invalid hour
goto hr_stop))
:min_stop
set min_stop=59
set /p min_stop=What minute to stop?
if "%min_stop%"=="b" goto hr_stop
if %min_stop% geq 0 (
if %min_stop% leq 59 (
if %min_stop% lss 10 set min_stop=0%min_stop%) else (
echo Invalid minute
goto min_stop))
:sec_stop
set /a sec_stop=59
set /p sec_stop=What second to stop?
if "%sec_stop%"=="b" goto min_stop
if %sec_stop% geq 0 (
if %sec_stop% leq 59 (
if %sec_stop% lss 10 set sec_stop=0%sec_stop%) else (
echo Invalid second
goto sec_stop))
echo.
set start_disp=%hr_start%:%min_start%:%sec_start%
set stop_disp=%hr_stop%:%min_stop%:%sec_stop%
echo Start time is %start_disp%.
echo Stop time is %stop_disp%.
echo.
:compare
set start_hr=%hr_start%*10000
set /a start_min=%min_start%*100
set /a stop_hr=%hr_stop%*10000
set /a stop_min=%min_stop%*100
set /a start_time=%start_hr% + %start_min% + %sec_start%
set /a stop_time=%stop_hr% + %stop_min% + %sec_stop%
if %stop_time% leq %start_time% (
echo End time must be at least one second after start time
pause
goto time_begin)
:time_confirm
echo.
set start_disp=%hr_start%:%min_start%:%sec_start%
set stop_disp=%hr_stop:~-2%:%min_stop%:%sec_stop%
echo Start time is %start_disp%.
echo Stop time is %stop_disp%.
echo.
set corr_time=blank
set /p corr_time=Times are correct?
if /i "%corr_time%"=="y" goto summary
if /i "%corr_time%"=="n" goto time_begin
goto time_confirm
As you can see, I have two ways I could search: an integer using hour, minute, and second, or a string using %start_disp% and %stop_disp%. Here is a sample line, and all lines follow the same pattern exactly up to this point in the line; after the final ], the pattern varies:
2013/10/30 00:00:13 [501014]CODELINE_INDICATION_MSG 192.168.013.254:5501 TX 41 bytes
solution with sed for Windows:
input file is sorted already:
sed -n "\#START TIME#,\#STOP TIME#p" input.txt>output.txt
input file is not sorted:
sort input.txt | sed -n "\#START TIME#,\#STOP TIME#p" >output.txt
example for a sorted file:
sed -n "\#2013/10/30 00:00:13#,\#2013/11/30 00:00:13#p" input.txt>output.txt

Resources