csePixelated
asked on
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?
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%
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-
findstr %findtext% %findfile%
for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a >> "Z:\OP\test-%month%-%year%
pause
I however now have another requirement, is it possible to only return lines that start with %dayil% ? Like an AND clause?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i see what i did...
ASKER
ok worked like a charm, thanks again bill
ASKER
@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
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%
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-
findstr %findtext% %findfile%
for /f "delims=" %%a in ('findstr %findtext% %findfile%') do echo %%a >> "Z:\OP\test-%month%-%year%
pause
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.
»bp
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%"
»bp
ASKER
Bill I appreciate the help, Ive got more to do so i keep breaking it into smaller problems.
Understand, good approach.
»bp
»bp
ASKER
@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%
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%
pause