Reputation: 37
I am trying to write a batch file that will extract lines 6000 to 6999 in a give text file. From googling I have come accross the following code - however this is giving me a blank output file.
@echo off
SetLocal EnableDelayedExpansion
type nul > nodedata.txt
set StartText=6000
set EndText=7000
set Flag=0
for /f "tokens=* delims=" %%a in ('type out.txt') do (
if /i "%StartText%" EQU "%%a" (set Flag=1)
if /i "%EndText%" EQU "%%a" (set Flag=0)
if !Flag! EQU 1 echo %%a >> nodedata1.txt
)
Any ideas as to where I am going wrong?
Upvotes: 0
Views: 1007
Reputation: 67326
This is a Batch solution that run faster...
@echo off
SetLocal EnableDelayedExpansion
set count=0
(for /F "skip=5999 delims=" %%a in (out.txt) do (
echo %%a
set /A count+=1
if !count! equ 1000 goto endLoop
)
) > nodedata1.txt
:endLoop
Upvotes: 1
Reputation: 31251
Here is a quick and simple pure batch solution
for /l %%a in (6000,1,6999) do (
more C:\file.txt +%%a >>C:\extracted.txt
)
Upvotes: 2
Reputation: 5732
You should install unxutils and then see answers for this question... Windows is just not made for text processing...
A Windows user...
Upvotes: 1