I have a batch script which will print the entire line of search string into a text file.
for %%i in (log.txt) do (
FINDSTR /G:pattern.txt %%i >> outpu
try this:
for /f "delims=:" %%a in ('findstr /in "error" log.txt') do set /a found=%%a
if not defined found (echo "error" not found&goto:eof)
set /a line1=found-1
set /a line2=found+1
for /f "tokens=1*delims=:" %%a in ('findstr /in "^" log.txt') do (
if %%a==%line1% >>output.txt echo(%%b
if %%a==%line2% >>output.txt echo(%%b
)