How do I get "FINDSTR" find a value between a specified range ? I set the "string": "20141001" and "20141030" . If within the *.TXT file exists "20141017", should return the "ERRORLEVEL" = 0.
EXEMPLE:
@echo off
SET DATE_STA=20141001
SET DATE_END=20141030
echo Looking for all the files in the folder
echo within the range from %DATE_STA% to %DATA_END% ...
echo.
:FINDING
findstr /r "%DATE_STA% to %DATA_END%" C:\Folder\*.txt
IF %ERRORLEVEL%==0 (
goto OKAY) else (
goto FAIL
)
:OKAY
cls
echo.
echo Located file that contains a value in the specified range.
echo.
pause
exit
:FAIL
cls
echo.
echo Any file located in this folder..
echo.
pause
exit
Use
findstr
with a regexp that catches only the strings you want:Of course this is a simplified regexp that will also catch
31
of October (which is bad) and the invalid00
and39
(but if your file contains only valid dates it's not a problem), so you'll have to write several regexps for each 10 day range.Or generate a list of the dates in a loop, write them to a file and use that file in
findstr
. Here's an example that generates two date scopes:20141001 20141030
and20151001 20151030
:The above solution will [erroneously] catch the numbers inside other bigger numbers like 22222220141001 so if this is undesirable here's a much slower but more reliable version:
I'm not aware of a good FINDSTR solution. But there is a simple solution using JREPL.BAT - a regular expression text processing utility that runs natively on any Windows machine from XP onward. It is pure script (hybrid batch/JScript) that does not require any 3rd party executables.
The solution uses a simple regular expression, coupled with a tiny bit of custom JScript code provided on the command line.