4- PRINT ONLY LAST WORD FROM OUTPUT FILE.
Find exact word from file and print upper and bottom line text and also read last word from file.
@echo off
setlocal EnableDelayedExpansion
::FINDSTR "butter" mylogfile.log
::findstr "ghee" mylogfile.log | findstr "butter"
rem Assemble the list of line numbers
set numbers=0
for /F "delims=:" %%a in ('findstr /I /N /C:"ghee" mylogfile.log ^| findstr "butter"') do (
set /A exactline=%%a, before=%%a-1, after=%%a+1
set "numbers=!numbers!!before!: !after!: "
set "BaseLine=!exactline!"
)
rem Search for the lines
::(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" mylogfile.log ^| findstr /B "%BaseLine%"') do echo %%b) > newmylogfile.txt
(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" mylogfile.log ^| findstr /B "%numbers%"') do echo %%b) > mylogfile.txt
::for /f "tokens=1*delims=:" %%G in ('findstr /n "^" mylogfile.txt') do if %%G equ 2 echo %%H >>mylogfile.txt
REM READ LAST LINE FROM OUTPUT FILE.
for /F "delims=" %%i in (mylogfile.txt) do set "xprvar=%%i"
REM PRINT ONLY LAST WORD FROM OUTPUT FILE.
FOR %%A IN (%xprvar%) DO SET last=%%A
echo 1^|%last% > mylogfile.txt
No comments:
Post a Comment