batch findtext match 2 criteria

I had this question after viewing batch findtext.

Thanks to Bill i now have this

@echo off

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-2%
echo year=%year%
set month=%date:~4,-8%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~7,-5%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datef=%hour%-%day%-%month%-%year%
set dayf=%month%-%day%-%year%
set dayil=%month%/%day%/%year%

echo datetimef=%datef%
echo %dayf%
echo %dayil%

pause

set findtext=/c:" DS-" /c:" DSA-"
set findfile="Z:\OP\exa\02-04-18 - Copy.P02"

findstr %findtext% %findfile%

for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a >> "Z:\OP\test-%month%-%year%.txt

pause

I however now have another requirement, is it possible to only return lines that start with %dayil% ? Like an AND clause?
LVL 1
csePixelatedAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Bill PrewIT / Software Engineering ConsultantCommented:
Try this approach.  The /r invokes regular expression mode.  The /b specifies that the match must be from the start (left end) of the line.  Then each /c is what you are looking for, either one of the two /c's matching is a hit.

In the /c text, we start with the date, then .* means zero or more of any character, then a space followed by your strings, like DSA-

set findtext=/r /b /c:"%dayil%.* DS-" /c:"%dayil%.* DSA-"

Open in new window


»bp

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
csePixelatedAuthor Commented:
nothing after the 1st pause, the batch just stops

@echo off

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-2%
echo year=%year%
set month=%date:~4,-8%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~7,-5%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datef=%hour%-%day%-%month%-%year%
set dayf=%month%-%day%-%year%
set dayil=%month%/%day%/%year%

echo datetimef=%datef%
echo %dayf%
echo %dayil%

pause

set findtext=/c:" DS-" /c:" DSA-"
set findtext=/r /b /c:"%dayil%.* DS-" /c:"%dayil%.* DSA-"

findstr %findtext% %findfile%

for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a >> "Z:\OP\test-%month%-%year%.txt

pause
csePixelatedAuthor Commented:
i see what i did...
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

csePixelatedAuthor Commented:
ok worked like a charm, thanks again bill
csePixelatedAuthor Commented:
@echo off

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-2%
echo year=%year%
set month=%date:~4,-8%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~7,-5%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

set datef=%hour%-%day%-%month%-%year%
set dayf=%month%-%day%-%year%
set dayil=%month%/%day%/%year%

echo datetimef=%datef%
echo %dayf%
echo %dayil%

pause

set findtext=/r /b /c:"%dayil%.* DS-" /c:"%dayil%.* DSA-"
set findfile="Z:\OP\exa\02-04-18 - Copy.P02"

findstr %findtext% %findfile%

for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a >> "Z:\OP\test-%month%-%year%.txt

pause
Bill PrewIT / Software Engineering ConsultantCommented:
And just as a bonus, a slightly smaller way to set the date time variables, that is more resistant to different localized date time formats.

rem Get current date and time in format: YYYYMMDDhhmmss.mmmmmm-zzz
set "Now="
for /f "tokens=* skip=1" %%B in ('wmic os get LocalDateTime') do (if not defined Now set "Now=%%B")
set "year=%Now:~2,2%" & set "month=%Now:~4,2%" & set "day=%Now:~6,2%" & set "hour=%Now:~8,2%" & set "min=%Now:~10,2%" & set "secs=%Now:~12,2%"

Open in new window


»bp
csePixelatedAuthor Commented:
Bill I appreciate the help, Ive got more to do so i keep breaking it into smaller problems.
Bill PrewIT / Software Engineering ConsultantCommented:
Understand, good approach.


»bp
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
Windows Batch

From novice to tech pro — start learning today.