Reputation: 31
There is a log file gettting generated and I have to find out whether the following lines are there are not?
Log file :
ftp>connected to server.
ftp> mget xyz*
200 Type set to A.
ftp> mget abc*
200 Set Type to A
ftp> bye
ANd i have to find whether the above log file has : "200 Type set to A.
ftp>"
Please let me know how to search the consecutive lines and in the second line I am trying to locate only a string.
Upvotes: 0
Views: 583
Reputation: 130849
I'm not sure if there is an empty line between each line or not. The solution below assumes there is NOT an empty line between each line. In other words, the solution below will match 2 lines, and the 2nd line must have at least one character.
@echo off
setlocal disableDelayedExpansion
::Define LF variable containing a linefeed (0x0A)
set LF=^
::Above 2 blank lines are critical - do not remove
::Define CR variable containing a carriage return (0x0D)
for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a"
::The above variables should be accessed using delayed expansion
setlocal enableDelayedExpansion
::regex "!CR!*!LF!" will match both Unix and Windows style End-Of-Line
findstr /rc:"!CR!*!LF!200 Type set to A!CR!*!LF!." log.txt >nul && (echo found) || echo not found
If you are attempting to match 3 lines with an empty line in the middle, then the last line needs to change to
findstr /rc:"!CR!*!LF!200 Type set to A!CR!*!LF!!CR!*!LF!." log.txt >nul && (echo found) || echo not found
For more information about searching across line breaks, as well as other cool FINDSTR features (and bugs!) see What are the undocumented features and limitations of the Windows FINDSTR command?
Upvotes: 1