Code: Select all
set "file=test.txt"
setlocal EnableDelayedExpansion
<"%file%" (
for /f %%n in ('type "%file%"^|find /c /v ""') do (
for /L %%i in (1 1 %%n) do (
set "LN=" & SET /P "LN="
ECHO Line %%n is !LN!
)
)
)
At first sight I expected the outer %%n "do loop" to iterate through each line in %file%
I now realize that the inner %%i loop has that task.
Does the outer loop only iterate through a wild card set %file%,
or can it initiate any sort of recovery action should SET /P "LN=" reads less lines than the file holds ?
(I have already seen that SET /P reads far too many lines when looking at UNIX text)
Is there any danger in this revision that avoids one level of code indentation
and allows %%j to start its count from 1001 instead of 1
(Sometimes I prefer a fixed 4 digit width count from 1001 through to 9999)
Code: Select all
set "file=test.txt"
setlocal EnableDelayedExpansion
SET BEGIN=1001
<"%file%" (
for /f %%n in ('type "%file%"^|find /c /v ""') do SET /A LINEND=%BEGIN%+%%n
for /L %%j in (%BEGIN%, 1, !LINEND!) do (
set "LN=" & SET /P "LN="
ECHO Line %%n is !LN!
)
)
Regards
Alan