I was wondering if someone could please help me with this.
I have a txt file called "cat.txt" in the text file i have this:
this
animal
is
a
cat
but
it's
not
my
cat
but
the
neighbors
cat
I looking for the code to find the word "cat" and to grab the line above, the "cat" line and the line below, so three lines.
And copy everything to a textfile, without the three lines.
Like this:
this
animal
is
it's
not
the
A got this code from somewhere and it grab's the three lines but outputs that to the textfile.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set lastLine=0
< %~1 > %~n1_nocat.txt (for /F "delims=:" %%a in (
'findstr /N /I /C:"cat" %1') do (
set /A skip=%%a-lastLine-1, lastLine=%%a+2
for /L %%i in (1,1,!skip!) do set /P line=
for /L %%i in (1,1,3) do set /P "line=!line!" & echo/
echo/
))
Could someone please help?