Reputation: 83
I want to read two lines of a big text document with a specified line number. But it always gives me the last line of the document instead of the 2 specified.
First I identify the line numbers:
for /f "delims=:" %%f in ('findstr /n /c:"= Boot Option" dump.txt') do set line=%%f
set /A Line1=%line%+4
set /A Line2=%line%+5
than I read the two lines:
for /f "skip=%line1%" %%l in (dump.txt) do set Boot1=%%l
for /f "skip=%line2%" %%l in (dump.txt) do set Boot2=%%l
echo %boot1% - %boot2%
I checked the line numbers, line1 = 33140 and line2 = 33141, those are the right lines, but I always get the last line of the document twice (which is 33532).
I also tested to place the number 33140 directly into the skip argument, but that also failed. Even setting a lower number like 25 in there will result in the last line of the document.
Upvotes: -1
Views: 45
Reputation: 83
OMG... its working.
for /f "skip=%line1% tokens=1,2 delims=]" %%a in (dump.txt) do set "Boot1=%%b"&goto nextline
:nextline
for /f "skip=%line2% tokens=1,2 delims=]" %%a in (dump.txt) do set "Boot2=%%b"&goto nextline
:nextline
echo %boot1% - %boot2%
Upvotes: 0