@echo off
:: Normal for+findstr statements ignore lines starting with semicolons
:: findstr /n .* After using delims=:, all colons at the beginning of the line will be ignored
:: There are also special symbols such as!, &, and. that need to be processed
:: The following code can accurately extract these sensitive characters
:: Solves the problem of the maximum recursive layer of setlocal (setlocal nests in pairs to process more than 15 lines of content)
:: Can calculate empty lines
:: code by jm 2006-12-12 thanks 3742668 CMD@XP
set num=0
for /f "delims=" %%i in ('findstr /n .* ') do (
set /a num+=1
set "str=%%i"
setlocal enabledelayedexpansion
echo !num! line: !str:*:=!
endlocal
)
pause
goto :eof
@echo off
:: When more than 15 lines of content, it will cause the problem of setlocal's maximum recursive layer
:: code by 3742668 2006-12-11 CMD@XP
@echo off
setlocal enabledelayedexpansion
set num=
for /f "eol= delims=" %%i in ('findstr .* ') do (
setlocal DISABLEDELAYEDEXPANSION
set "tmpstr=%%i"
setlocal enabledelayedexpansion
set /a num += 1
set "!num!=!tmpstr!"
)
for /l %%i in (1,1,%num%) do echo %%i line: !%%i!
pause
exit /b 0
@echo off
:: The content with exclamation mark cannot be extracted correctly
:: code by jm 2006-12-11 CMD@XP
set num=0
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('findstr /n .* ') do (
set /a num+=1
set "str=%%i"
echo !num! line: !str:*:=!
)
pause
goto :eof
@echo off
:: The result should be enclosed in quotes
:: code by jm 2006-12-11 CMD@XP
set num=0
::setlocal enabledelayedexpansion
for /f "delims=" %%i in ('findstr /n .* ') do (
set /a num+=1
set "str=%%i"
call :display
)
pause
goto :eof
:display
echo %num% line: "%str:*:=%"
goto :eof
Contents
:abc
::xy
;;;ef &
;:;
::;;
&
^
!<
!
%
"
""
'
test
abc