CopyCode The Code is as follows: @ echo off
: Normal for + findstr statements ignore rows starting with a semicolon
: Findstr/n. * after delims =: is used, all colons at the beginning of the line are ignored.
: Yes! , &,. And other special symbols need to be processed
: The following code accurately extracts these sensitive characters:
: Solved the problem of setlocal maximum recursion layer (this problem occurs when setlocal nesting processes more than 15 rows of content)
: Empty rows can be calculated.
: Code by JM 2006-12-12 thanks 3742668 cmd @ XP
Set num = 0
For/F "delims =" % I in ('findstr/n. * test.txt ') Do (
Set/a num + = 1
Set "str = % I"
Setlocal enabledelayedexpansion
Echo No! Num! Row :! STR: *: =!
Endlocal
)
Pause
Goto: EOF
@ Echo off
: When there are more than 15 lines of content, it will bring about the setlocal maximum recursion layer problem.
: Code by 3742668 2006-12-11 cmd @ XP
@ Echo off
Setlocal enabledelayedexpansion
Set num =
For/F "EOL = delims =" % I in ('findstr. * a.txt ') Do (
Setlocal disabledelayedexpansion
Set "tmpstr = % I"
Setlocal enabledelayedexpansion
Set/a num + = 1
Set "! Num! =! Tmpstr! "
)
For/L % I in (1,1, % num %) Do echo row % I :! % I!
Pause
Exit/B 0
@ Echo off
: The content with an exclamation point cannot be extracted correctly.
: Code by JM 2006-12-11 cmd @ XP
Set num = 0
Setlocal enabledelayedexpansion
For/F "delims =" % I in ('findstr/n. * test.txt ') Do (
Set/a num + = 1
Set "str = % I"
Echo No! Num! Row :! STR: *: =!
)
Pause
Goto: EOF
@ Echo off
: The results should be enclosed in quotation marks.
: Code by JM 2006-12-11 cmd @ XP
Set num = 0
: Setlocal enabledelayedexpansion
For/F "delims =" % I in ('findstr/n. * test.txt ') Do (
Set/a num + = 1
Set "str = % I"
Call: Display
)
Pause
Goto: EOF
: Display
Echo row % num %: "% STR: *: = %"
Goto: EOF
Test.txt content
: ABC
: XY
; EF &
;:;
::;;
&
^
! <
!
%
"
""
'
Test
ABC