1.

Solve : findstr to validate successful run and copy selected lines to archive?

Answer»

At the bottom of this post is my input file (sarweekly.log) to findstr.
It is a log of output messages from a batch program execution.
Just before the file (sarweekly.log) is a listing of my BAT file (xxxxxx).
 
I have two findstr in that seem to be working, however, using ECHO on
to debug I noticed the the 1st findstr starts at the beginning of the input.
When it discovers the string it drops through the IF and EXECUTES the
2nd findstr. The 2nd findstr I thought would start over at the beginning
of the input. However, it starts at the next line of the input.  OK......
It works only because the 2nd findstr is looking for what is on the very
next line in the file.
Not having any DOS Command language exerience before being assigned
this work my mind see a problem I need experience and knowledge of findstr
or some other DOS Command to fix.

I was expecting each findstr to start at the beginning. I am sure you understand that.
Once the 2nd findstr found its string
I planned to issue multiple other findstr to search for strings:
 "Form identifier " and 'E-File"
as findstr discovered test I was going to do an IF
to  copy that line with the >> to an archive log
 
Now my mind is not even sure if this design is possible.
 
I hope all you experiences people have pitty but I do
expect you will get a laugh out of my situation. It is
good to laugh, even at my expense, but especially on Fridays.
 
Thank you to anyone who is investing their time looking and responding to my post.

HERE IS THE DOCUMENTATION
BEGINNING OF DOS Command BAT File
set SCRIPTLOG=D:\EFILING\INPROCESS\archives
echo . >> %SCRIPTLOG%
echo "= = = = = = = = = = = = = = = = = = = = = = = = = = = = =" >> %SCRIPTLOG%
echo . >> %SCRIPTLOG%
echo . - BEGIN. >> %SCRIPTLOG%
echo Start PROCESS COMPLETE TEST %date time% >> %SCRIPTLOG%
rem ========= Did program create a file =====================
findstr "E-file RCM_SAR_Form_" D:\EFILING\INPROCESS\sarwklymsgs.log
If %errorlevel% neq 0 THEN GoTo NoSAR
rem ==============================================
 
rem ======= YES THEN did program complete successfully ==========
findstr "Process Completed." D:\EFILING\INPROCESS\sarwklymsgs.log
if %errorlevel% neq 0 GoTo BadEnd
rem ==============================================
rem ----- HERE IS WHERE I FOUND OUT findstr was not starting over/
rem ----- at the beginning of file everytime.  It what prompted me to post
rem ----- IF THERE IS A WAY FOR FORCE A findstr to start at the beginning
rem ----- of a file I hope someone knows. Maybe my code could work Ha Ha!
rem ----- Another good laugh for you experienced people on a Friday
rem ===== Loop through log file and archive selected lines =-==========
:MvArcf
findstr " Form identifier " D:\EFILING\INPROCESS\sarwklymsgs.log
if %errorlevel% equ 0
copy /y  current line from findstr match >> D:\EFILING\LOGS\sarformsids.log
:MvArce
findstr "E-file RCM_SAR_Form_" D:\EFILING\INPROCESS\sarwklymsgs.log
if %errorlevel% equ 0
copy /y  current line from findstr match >> D:\EFILING\LOGS\sarfileids.log
GoTo END
rem ================================================

rem ================================================
:BadEnd
rem Program ended with errors
set errorlevel=1
GoTo END
rem ================================================
 
rem =================================================
:NoSAR
rem No Cases in Ready for Report, so NO SAR Form file is written
rem Force completion of entire following automation
rem =============================================================
set errorlevel=2
rem =============================================================
:END
echo STOP PROCESS COMPLETE TEST  %date% %time% >> %SCRIPTLOG%
echo . - END. >> %SCRIPTLOG%
END OF DOS Command BAT File
BEGINNING OF SARWKLYMSGS.LOG  (Input File). - BEGIN. 
Start utility THU 01/23/2014 15:08:38.37 
Thu Jan 23 15:08:39 CST 2014 - Connecting to the RCM server. [https://dev-ercm-ws-dns.com:10702/RCM]
  Form identifier 0000000909 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001005 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001101 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001119 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001009 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001121 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001111 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001401 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
  Form identifier 0000001403 added to e-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST.
E-file RCM_SAR_Form_01-23-2014 15-08_TBSATEST created from 9 form(s), its size is 102KB.
Process completed.
Stop utility Thu 01/23/2014 15:08:47.54
. - END.
END OF SARWKLYMSGS.LOG  (Input File)There will have been errors on the console - THEN is not used in batch code.

If %errorlevel% neq 0 THEN GoTo NoSAR


When you post code, use code tags around it - highlight the code and click on the # icon above in the editor.


This syntax is incorrect, and a correct construction would be on the same line too.

Code: [Select]if %errorlevel% equ 0
copy /y  current line from findstr match >> D:\EFILING\LOGS\sarformsids.log Quote from: foxidrive on April 18, 2014, 10:38:46 AM

When you post code, use code tags around it - highlight the code and click on the # icon above in the editor.
Or you can actually type out the BB CODE tags.
[­code]Batch code goes here[­/code]How do any of your FINDSTR commands make you think it is not searching the file from the beginning of the file?

Every time you execute the FINDSTR command it is searching the file from the beginning and looking for your search parameter. Quote from: tommyb on April 18, 2014, 10:26:57 AM
2nd findstr. The 2nd findstr I thought would start over at the beginning
of the input. However, it starts at the next line of the input.

How do you know this?
Salmon Trout,
I say it because I turn set echo on.
The first findstr listed every line it searched.
The second findstr only listed the on line (which is the next line in the log file).
I thought the 2nd findstr was telling me it started where the 1st findstr ended.
 
So please educate me.Golly gee. Considering your first FINDSTR command basically finds most of the lines in your file I guess I can see how that would be confusing. It is going to output what you are searching for. What did you expect FINDSTR to do? Quote from: tommyb on April 18, 2014, 02:27:56 PM
The first findstr listed every line it searched.
The second findstr only listed the on line (which is the next line in the log file).

findstr searches the entire file for the text you provide. 
It can show various things depending on which switches you use, such as

The text you provide
Lines that do not contain the text you provide
Lines of text with the line number at the beginning
etc




Discussion

No Comment Found