I am trying to find a command or batch file that can find specific text in a line of a log file. When the text is found, I want to include the previous 3 lines before the text that is found. I saw some examples using a FOR loop but I can only get one token and not the previous lines. Is there a way to do this without utilities in a batch file?
@echo off
svn log https://sub.mycompany.com/svn/company-dev/ > c:\temp\svn.txt
setlocal EnableDelayedExpansion
rem Assemble the list of line numbers
set JiraID=%1
set numbers=
for /F "delims=:" %%a in ('findstr /I /N /C:"%JiraID%" c:\temp\svn.txt')
do (
set /A beforeo=%%a, before=%%a-1, before2=%%a-2
set "numbers=!numbers!: !beforeo!: !before!: !before2!:"
)
rem Search for the lines
(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" c:\temp\svn.txt ^|
findstr /B "%numbers%"') do echo %%b)
del c:\temp\svn.txt
I actually do not want to dump the SVN log if there is a way to do it inline with SVN LOG command. The file created has spaces when outputed to text,
The output being read has spaces between lines as well and the output sometimes does not include the "-----" lines so it was tricky trying to collect the correct lines. Any ideas?
------------------------------------------------------------------------
r132279 | USERID | 2014-04-30 12:59:09 -0700 (Wed, 30 Apr 2014) | 3 lines
Removed unused "Calculated Fields" column entry.
Jira ID: JIRA-977
------------------------------------------------------------------------